//根据id去重
treeList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() ->
new TreeSet<>(Comparator.comparing(Tree::getId))),ArrayList::new))
//根据id和name去重
treeList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() ->
new TreeSet<>(Comparator.comparing(
t -> t.getId()+";"+t.getName()))),ArrayList::new))
Java中List根据字段去重
最新推荐文章于 2024-05-21 10:59:50 发布