简单的set和list之前相互转换达到去重的方法就不再记录了。
直接上代码
//去重
ArrayList<XXX> collect = resultList.stream().collect(
collectingAndThen(
toCollection(() -> new TreeSet<>(Comparator.comparing(XXX::getId))),
ArrayList::new)
);
如果多条件:
ArrayList<XXX> collect = resultList.stream().collect(collectingAndThen(
toCollection(() -> new TreeSet<>(
Comparator.comparing(o -> o.getXXX() + "#" + o.getXXXX() + "#" + o.getXXXXX()))), ArrayList::new)
);