1.Stream是元素的集合,这点让Stream看起来用些类似Iterator;
2.可以支持顺序和并行的对原Stream进行汇聚的操作;
1.根据对象属性过滤list中重复对象
ArrayList agentCollect = agentList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(Agent::getAgentName))), ArrayList::new));
2.根据对象属性过滤list中重复对象多个属性
ArrayList agentToCsoCollect = agentToCsoList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>( Comparator.comparing(p->p.getAgentPromotionId() + “;” + p.getCsoPromotionId()))), ArrayList::new));
3.获取list中属性相同得对象,contains取两个集合交集
List list = hashSet.stream().filter(s -> integers.contains(s.getSn())).collect(Collectors.toList());
4.获取list中属性不相同得对象
List list = hashSet.stream().filter(s ->!integers.contains(s.getSn())).collect(Collectors.toList());
5.根据list中对象属性排序
List checkExportList = list.stream().sorted(Comparator.comparing(CheckExport::getTime)).collect(Collectors.toList());
6.获取list集合中对象某一个属性形成集合
List list2 = list.stream().map(A::getAge).collect(Collectors.toList());//未去重
List list3 = list.stream().map(A::getAge).distinct().collect(Collectors.toList());//已去重



