java - What name to give to objects when adding to ArrayList -
i have container class array list defined person object.
the person using program asked register person , have create object person, give name, lastname , age user inputed , after add arraylist.
my question is, when creating person object, can give same name every object add? or have name them person1, person2, etc?
if so, how?
thanks
no, don't have give them different names. doing defeat purpose of using collection. can following:
person p = new person(...); // set name, age, etc. list.add(p);
each time that, new person
created , added list. think of name p
temporary variable can discarded.
Comments
Post a Comment