List unique = persons.stream().collect( Collectors.collectingAndThen( Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(Person::getName))), ArrayList::new)
// 根据name,sex两个属性去重
List<Person> unique = persons.stream().collect(
           Collectors. collectingAndThen(
                    Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getName() + ";" + o.getSex()))), ArrayList::new)

filter()过滤列表

List<Person> filterList = persons.stream().filter(p -> p.getSex().equals(1)).collect(Collectors.toList());
List转Map

从一个Person对象的List集合,取出idname组成一个map集合

Map<String, String> collect = list.stream().collect(Collectors.toMap(p -> p.getId(), p -> p.getName()));
从 List 中取出某个属性的组成 list 集合
//1.提取出list对象中的一个属性
List<String> stIdList1 = stuList.stream().map(Person::getId).collect(Collectors.toList());
//2.提取出list对象中的一个属性并去重
List<String> stIdList2 = stuList.stream().map(Person::getId).distinct().collect(Collectors.toList());
需要对一个List中的对象进行唯一值属性去重,属性求和,对象假设为BillsNums,有id、nums、sums三个属性,其中id表示唯一值,需要nums与sums进行求和,并最后保持一份。例如说:(“s1”, 1, 1),(“s1”,2,3),(“s2”,4,4), 求和并去重的话,就是(“s1”, 3, 4),(“s2”,4,4)
对象与属性
class BillsNums ...
                                    Java8新特性 实现 举例
List<LinkedHashMap<String, Object>> effective = syncCertList.stream().filter(el->{
Object courseCode = el.get("courseCode");//课程编号
Object employeeCode = el.get("employeeCode");//人员工号
boolean yitongbu = resTwCourseRecordVie
                                    1.通过指定字段分组
classEntities.stream().collect(Collectors.groupingBy(ClassEntity::getGrade));
2.java8去重(根据年级和专业,当年级和专业都相同的情况下看做是重复数据)
List<ClassEntity> distinctClass = classEntities.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() 
                                    Java 8 是一个非常成功的版本,这个版本新增的Stream,配合同版本出现的 Lambda ,给我们操作集合(Collection)提供了极大的便利。那么什么是StreamStream将要处理的元素集合看作一种流,在流的过程中,借助Stream API对流中的元素进行操作,比如:筛选、排序、聚合等。Stream可以由数组或集合创建,对流的操作分为两种:1. 中间操作,每次返回一个新的流,可以有多个。2.  终端操作,每个流只能进行一次终端操作,终端操作结束后流无法再次使用。...
// 筛选短信黑名单数据
List smsBlackListSet = allBlacklist.stream().filter(sms -> (sms.getCorpcode().equals(corpCode) &&
        sms.getBltype().equals(MessageTypeEnum.SMS.getKey()) && sms.getSvrtype().equals(bus))).collect(Collectors.toList());
// 解释:本次对allBlacklist集合过滤条件三个:sms.getCorpcode()