Suppose I have an object that looks like:
public class Obj {
String foo;
String bar;
}
If I create an arraylist of type Obj and populate it, is there a way I can return a list of all the objects in the array’s foo attribute from the ArrayList?
EDIT: I should have been more clear, I did not want to do this via iteration
You’ll have to iterate through your
List<Obj>and collate the foo entries into a newListe.g.
or for Java 8 and beyond, use streams thus: