Java merges list method instance code
This article introduces the relevant knowledge of "java merge list method instance code". In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!
List includes the List interface and all the implementation classes of the List interface. Because the List interface implements the Collection interface, the List interface has all the common methods provided by the Collection interface, and because the List is a list type, the List interface also provides some common methods suitable for itself.
method one
List reduce = list.stream() .map(x -> x.getChildren()) .reduce(new ArrayList(), (all, item) -> { all.addAll(item); return all; }); System.out.println(reduce);
methodology II
List collect = list.stream() .map(Employee::getChildren) .flatMap(Collection::stream) .distinct().collect(Collectors.toList());----------------------------List childrens1 = new ArrayList();for (long i =0;i