java小笔记,List实体类对象的去重
// 去除重复的数据
ArrayList<**实体类**> collect = orderPOList.stream().collect(Collectors.collectingAndThen(
Collectors.toCollection(() -> new TreeSet<>(
Comparator.comparing(
// 对象的某一个属性
**实体类::getId**))), ArrayList::new));
参考了其他dalao的文,mark一下方便自己使用,主要用在mybatis的LambdaQueryWrapper查到的数据List,对某值做去重。
比如人员信息表,mybatisplus查询的时候去重过于麻烦或者自定义sql需求复杂的时候用用,不是太建议。去重人员表里name = 张三的数据。
collect是去重后的list。
java8以上使用*!!!