1.
List<Children> reduce = list.stream()
.map(x -> x.getChildren())
.reduce(new ArrayList<>(), (all, item) -> {
all.addAll(item);
return all;
});
System.out.println(reduce);

2.
List<Children> collect = list.stream()
.map(Employee::getChildren)
.flatMap(Collection::stream)
.distinct().collect(Collectors.toList());
----------------------------
List<Children> childrens1 = new ArrayList<>();
for (long i =0;i<10;i++){
childrens1.add(new Children(i,"x".concat(i+"")));
}
List<Children> childrens2 = new ArrayList<>();
for (long i =100;i<110;i++){
childrens2.add(new Children(i,"x".concat(i+"")));
}
Employee mazi = new Employee("麻子", 90, 989.2);
mazi.setChildren(childrens1);
Employee lisi = new Employee("李四", 10, 1000.1);
lisi.setChildren(childrens2);
List<Employee> list = Arrays.asList(mazi,lisi);
 posted on 2020-01-02 23:06  改变一下  阅读(4791)  评论(0编辑  收藏  举报