我正在学习lambda表达式。我想从另一个人的名单中选出20岁以上的人。
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);
我的印象中,只有前两个参数是足够的ArrayList::new
和ArrayList::add
。
ArrayList::addAll
我的示例中如何以及何时使用第三个参数?
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句