Java8

1.去重

// 根据UserName去重
        List<UserEntity> distinct2 = userEntities.stream().collect(
                Collectors.collectingAndThen(
                        Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(UserEntity::getUserName))), ArrayList::new)
        );
        // 根据UserName + Worknum 去重
        List<UserEntity> distinct3 = userEntities.stream().collect(
                Collectors.collectingAndThen(
                        Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(e-> e.getUserName() + ";" + e.getWorknum()))), ArrayList::new)
        );

 

posted @ 2019-04-27 11:02  小白个人成长记  阅读(220)  评论(0编辑  收藏  举报