If you want to call a method on all objects from your list, you need to iterate over them first and call the method on each element. Let's say your list looks like this
List<person> peopleHolder = new ArrayList<person>(); peopleHolder.add(new person()); peopleHolder.add(new person());
Now we have two people on the list, and we want to establish their names. We can do it like this:
for (int i=0; i<list.size(); i++){ list.get(i).setName("newName"+i);
or using advanced for loop
int i=0; for (person p: peopleHolder){ p.setName("newName" + i++); }
By the way, you should adhere to the Java Naming Convention and use the camelCase style. Classes / interfaces / enumerations must begin with an uppercase letter, for example Person , the first token of the variable / method name must begin with lowercase, and others with an uppercase, for example peopleHolder .
source share