Let's take a list of Person
defined as
- Name
- Surname
- Age
I want the max(age) in a List<Person>
.
I could iterate on this list and manually keep the max :
Integer max = null;
for(Person p : list) {
if(max == null || max < p.getAge()) {
max = p.getAge();
}
return max;
}
But I feel that there might exist a combination of Guava methods which can do it for me. If I write a Function<Person, Integer>
, is there a ready-to-use method to get the max from the list?