//根据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-03-10 22:40:40 发布