java list列表根据指定字段去重
作者:互联网
1.List指定字段去重
//indexCode为去重字段
hkDoorList.stream().collect(
Collectors.collectingAndThen(
Collectors.toCollection(() ->
new TreeSet<>(Comparator.comparing(HkDoorVO::getIndexCode))), ArrayList::new)
);
2.把List中的某个数据单独抽出某个字段列,并去重
List<String> indexCodes = hkDoorList.stream().map(HkDoorVO::getIndexCode).distinct().collect(Collectors.toList());
//去重
list=list.stream().distinct().collect(Collectors.toList());
标签:java,Collectors,stream,list,List,collect,字段 来源: https://www.cnblogs.com/lovemelucky/p/16419159.html