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);

相关文章:

  • 2022-12-23
  • 2021-11-14
  • 2021-12-31
  • 2022-12-23
  • 2021-12-03
  • 2021-08-19
猜你喜欢
  • 2022-12-23
  • 2021-11-28
  • 2022-02-17
  • 2021-11-19
  • 2022-01-10
  • 2021-07-10
相关资源
相似解决方案