当前位置:网站首页>从list转化成map的时候,如果根据某一属性可能会导致key重复而异常,可以设置处理这种重复的方式
从list转化成map的时候,如果根据某一属性可能会导致key重复而异常,可以设置处理这种重复的方式
2022-07-02 17:26:00 【yuhui66666688gfbfdy】
从list转化成map的时候,如果根据某一属性可能会导致key重复而异常,可以设置处理这种重复的方式--java8中的是二者选其一,有其他要求其他方式实现
collect(Collectors.toMap(
Map.Entry::getKey, ---key
Map.Entry::getValue, ---value
(oldVal, newVal) -> oldVal, ---用哪一个覆盖
LinkedHashMap::new ---新的结果赋予的对象
)
tData = tData.entrySet().stream().sorted(new Comparator<Map.Entry<String, List<R>>>() {
@Override
public int compare(Map.Entry<String, List<R>> o1, Map.Entry<String, List<R>> o2) {
try {
Date d1 = DateUtil.convertStringToDate(o1.getKey(), "yyyy-MM");
Date d2 = DateUtil.convertStringToDate(o2.getKey(), "yyyy-MM");
return d1.compareTo(d2);
} catch (Exception e) {
e.printStackTrace();
}
return 0;
}
}).collect(Collectors.toMap(
Map.Entry::getKey,
Map.Entry::getValue,
(oldVal, newVal) -> oldVal,
LinkedHashMap::new
));
边栏推荐
- 谷歌官方回应:我们没有放弃TensorFlow,未来与JAX并肩发展
- UE4 用spline畫正圓
- The student Tiktok publicized that his alma mater was roast about "reducing the seal of enrollment". Netizen: hahahahahahahaha
- AI开发调试系列第二弹:多机分布式调测探索之旅
- Nm02 nm module call sequence diagram and code interpretation independent of bus protocol
- SQL training 2
- 学习八股文的知识点~~1
- Installation of thingsboard, an open source IOT platform
- Thoroughly understand the point cloud processing tutorial based on open3d!
- 拦截器与过滤器的区别
猜你喜欢
Looking for innocence in New York -- a beautiful day at the discovery center of Legoland, New Jersey
Leetcode (81) -- search rotation sort array II
Redis(7)----数据库与过期键
Responses of different people in technology companies to bugs | daily anecdotes
全链路数字化转型下,零售企业如何打开第二增长曲线
在纽约寻找童真——新泽西州乐高乐园探索中心的美好一天
迷你高尔夫球场:伦敦休闲旅游好去处
Simulateur nightGod + application de test de capture de paquets Fiddler
文字编辑器 希望有错误的句子用红色标红,文字编辑器用了markdown
Ali was wildly asked by the interviewer on three sides. Redis dared not write 'proficient' on his resume anymore
随机推荐
Slam | how to align timestamps?
鸿蒙第四次学习
StretchDIBits函数
阿里三面被面试官狂问Redis,简历上再也不敢写'精通'了
【愚公系列】2022年07月 Go教学课程 001-Go语言前提简介
问题包含哪些环节
昨天阿里学长写了一个责任链模式,竟然出现了无数个bug
LightGroupButton* sender = static_cast<LightGroupButton*>(QObject::sender());
Excel如何进行隔行复制粘贴
新加坡暑假旅遊攻略:一天玩轉新加坡聖淘沙島
UE4 draw a circle with spline
How to set vscode to delete the whole line shortcut key?
Websocket of Web real-time communication technology
夜神模擬器+Fiddler抓包測試App
How to copy and paste interlaced in Excel
电商系统中常见的 9 大坑,你踩过没?
iptable端口重定向 MASQUERADE[通俗易懂]
Hongmeng's fourth learning
Thoroughly understand the point cloud processing tutorial based on open3d!
What is cloud primordial? This time, I can finally understand!