jdk8中如何对List去重呢?
下文笔者讲述jdk8中list去重的方法及示例分享,如下所示
list去重
可使用stream中的Collectors方法
例:List去重的示例
public static List<Map<String, Object>> duplicateKey(List<Map<String, Object>> list) {
if (ObjectUtil.isNotEmpty(list)) {
list = list.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(
() -> new TreeSet<>(Comparator.comparing(itemMap -> itemMap.get("key").toString()))), ArrayList::new));
}
return list;
}
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


