jdk8 按照属性中某一个字段去重


//day 为user的一个属性
List<User> setList = eachUser.stream()
.collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(User::getDay))), ArrayList::new));

 

 

 

//根据多个字段列去重
        ars = ars.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(
                () -> new TreeSet<AccountRole>(Comparator.comparing(o -> o.getAccountId() + ";" + o.getRoleId()))), ArrayList::new));

 

posted @ 2021-05-12 09:39  君子笑而不语  阅读(657)  评论(0编辑  收藏  举报