lambda操作arrayList

发布时间 2023-03-22 21:09:18作者: 青竹玉简
//多个集合合并,得到一个新的集合
 List<T> list= Stream.of(list1, list2, ...).flatMap(Collection::stream).collect(Collectors.toList());

  

//集合根据某一属性去重,得到一个新的集合
List<T> newList = list.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() ->new TreeSet<>(Comparator.comparing(T::属性))), ArrayList::new));

  

//获取一个集合中,某个对象指定属性的集合
List<Integer> msisdnList =list.stream().map(T::指定属性).collect(Collectors.toList());