If you want to call some method at all objects from your list you need to iterate over them first and invoke method in each element. Lets say your list look like this
List<person> peopleHolder = new ArrayList<person>();
peopleHolder.add(new person());
peopleHolder.add(new person());
Now we have two persons in list and we want to set their names. We can do it like this
for (int i=0; i<list.size(); i++){
list.get(i).setName("newName"+i);//this will set names in format newNameX
}
or using enhanced for loop
int i=0;
for (person p: peopleHolder){
p.setName("newName" + i++);
}
BTW you should stick with Java Naming Conventions and use camelCase style. Classes/interfaces/enums should starts with upper-case letter like Person
, first token of variables/methods name should start with lower-case but others with upper-case like peopleHolder
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…