Reducing persons by ages

Report a typo

Given a list of persons:

List<Person> persons = Arrays.asList(
        new Person("Mary", 18),
        new Person("John", 21),
        new Person("Andrew", 31),
        new Person("Julia", 19)
);

Each person has a name (String) and an age (Integer).

What person will be returned by the following code? Select by the person name.

Person person = persons.stream()
        .reduce(new Person("DEFAULT", 0), (p1, p2) -> p1.getAge() > p2.getAge() ? p1 : p2);
Select one option from the list
___

Create a free account to access the full topic