Vswe's Summer Courses | You're not logged in. Sign up or log in | Server time: | Donate
One can now see other persons' badge hunts. Simply head over to their profiles to access them.

Go back to course page

Thinking with objects

Object orientated programming in Java

create multiple objects in a for loop

  • 2013-07-21 17:12:08
    The problem i have is that i want to create a multiple objects but the amount is entered by the user so unknown to me is there a way to give different names to objects in a forloop i know its pretty unclear right now so this is an example

    for (int p = 0; p < nextValidInteger(1, Integer.MAX_VALUE); p++) {
                AG something = new AG(nextValidInteger(1, Integer.MAX_VALUE), Agname(), numberboys, numbergirls);
    can i change the something into a different name everytime i loop through

    i hope i made it somehow clear what i want and if that is covered in a course i haven't gotten to im sorry. Thank you for helping me out.
  • 2013-07-21 17:38:59
    I'm not entirely sure what you mean but I guess you can just store it in an array.
  • 2013-07-22 07:31:51
    yup, vswe is right. you can just store it in an array.
  • 2013-08-26 03:07:19
    Like Vswe says, use arrays, those are very useful. If you don't know how to do it, I'm sure Vswe covered it in one of his videos, or you can just search on google: ArrayList on java, or something like that.
  • Log in or sign up to reply to this thread