Let's say I have an ArrayList of objects. For example: ArrayList<Person> personList
, where each Person
has 2 class variables String name
and int age
. These variables each have their own getter methods getName()
and getAge()
.
What is the simplest way to retrieve an array (or ArrayList) of int ages[]
?
Note this question is similar to the verbosely titled "Retrieve an array of values assigned to a particular class member from an array of objects in java", though without the arbitrary restriction on for-loops, and using an ArrayList instead of an Array.