当前位置: 代码迷 >> 综合 >> java8根据元素属性进行列表去重
  详细解决方案

java8根据元素属性进行列表去重

热度:0   发布时间:2024-02-28 09:25:52.0

直接上代码

//根据name和value去重
List<Label> distinctLabels = allLabels.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getName() + ";" + o.getValue()))
), ArrayList::new));