美文网首页
java 对象根据属性去重

java 对象根据属性去重

作者: androidfan | 来源:发表于2022-04-13 10:51 被阅读0次

java 对象去重

  List<JzInfo> List = jzInfoList.stream()
                        .collect(Collectors.collectingAndThen(
                                Collectors.toCollection(() ->
                                        new TreeSet<>(Comparator.comparing(
                                                o -> o.getLac() + ";" + o.getCid()))),
                                ArrayList::new));

实体类需要重写hashCode() 和 eqauls()

image.png

如此即可

相关文章

网友评论

      本文标题:java 对象根据属性去重

      本文链接:https://www.haomeiwen.com/subject/cbtnsrtx.html