工作纪实_28-lambda复杂表达式

1.取集合嵌套的集合中,对应对象的某个值,形成list
list.stream().flatMap(x->x.getGoodsList().stream()).map(x->x.getId()).collect(Collectors.toList());

2.按某个属性分组,并按另一个属性取最大
studentList.stream()
.collect(Collectors.toMap(Student::getClassId, Function.identity(),
(c1, c2) -> c1.getAge() > c2.getAge() ? c1 : c2))
.values();

猜你喜欢

转载自blog.csdn.net/u013553309/article/details/127201363