0
点赞
收藏
分享

微信扫一扫

java8 List去重

jjt二向箔 2022-03-21 阅读 152
java后端

一、去除List中重复的String

List uniqueStr = list.stream().distinct().collect(Collectors.toList());

二、按对象属性去重

 users = users.stream().collect(
                collectingAndThen(
                        toCollection(() -> new TreeSet<>(Comparator.comparing(UserInDeptDto::getUserId))), ArrayList::new)
        );
举报

相关推荐

0 条评论