天天看点

java list 根据对象某些字段去重

根据DeptType、UserPosition 两个属性去重 

list.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getDeptType() + ";" + o.getUserPosition()))), ArrayList::new));