I'm learning about lambda expressions. From a list of people, I want another list with the people who are older than 20 years.
final List<Person> people = Arrays.asList(
new Person("John", 10),
new Person("Greg", 30),
new Person("Sara", 20),
new Person("Jane", 15));
List<Person> olderThan20 =
people.stream()
.filter(person -> person.getAge() > 20)
.collect(ArrayList::new,
ArrayList::add,
ArrayList::addAll);
I have the impression that only the first two parameters are sufficient ArrayList::new
and ArrayList::add
.
How and when is used the third parameter ArrayList::addAll
on my exemple?