List使用stream进行去重

根据某一字段进行去重
List<Entity> arrays = arr.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(Entity :: getId))), ArrayList::new));

  

posted @ 2023-03-13 20:42  歳月  阅读(107)  评论(0)    收藏  举报