List<Map<String, Object>> map根据某个属性去重

dataList = dataList.stream().collect(Collectors.collectingAndThen(
				Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(p -> (String) p.get("code")))),
				ArrayList::new));

原理:

new TreeSet<>(Comparator.comparing(p -> (String) p.get("code")))
利用Set集合的元素不重复的特点,构造一个带有构造函数的TreeSet,使用Comparator定义元素的排序顺序:

Collectors.toCollection(TreeSet::new)
返回一个Collector,将输入的元素按照处理的顺序放到新的Collection里面

Collectors.collectingAndThen()

调整Collector,执行另外的转换操作

https://blog.csdn.net/MD_MushRoom/article/details/130752667

map 深拷贝
Map<String,Object> mpFor = new HashMap<>(mpKw);
posted @   寒冷的雨呢  阅读(119)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示