当前位置:网站首页>从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
));
边栏推荐
- The text editor hopes to mark the wrong sentences in red, and the text editor uses markdown
- R language dplyr package filter function filters dataframe data. If the name of the data column (variable) to be filtered contains quotation marks, you need to use!! SYM syntax processing, otherwise n
- 哪个券商公司网上开户佣金低又安全又可靠
- IPtable port redirection masquerade[easy to understand]
- Yesterday, Alibaba senior wrote a responsibility chain model, and there were countless bugs
- 鸿蒙第四次学习
- Nm02 nm module call sequence diagram and code interpretation independent of bus protocol
- 【每日一题】第二天
- Redis(7)----数据库与过期键
- R语言使用epiDisplay包的lsNoFunction函数列出当前空间中的所有对象、除了用户自定义的函数对象
猜你喜欢
How to enable the run dashboard function of idea
Leetcode interview question 17.01 Addition without plus sign
UE4 draw a circle with spline
【每日一题】第一天
Web版3D可视化工具,程序员应该知道的97件事,AI前沿论文 | 资讯日报 #2022.07.01
[daily question] first day
Redis (6) -- object and data structure
Yesterday, Alibaba senior wrote a responsibility chain model, and there were countless bugs
开源物联网平台ThingsBoard的安装
学生抖音宣传母校被吐槽“招生减章”,网友:哈哈哈哈哈哈
随机推荐
The difference between SLC, MLC, TLC and QLC NAND SSD: which is better?
Troubleshooting ideas that can solve 80% of faults
Web实时通信技术之Websocket
promise 和 Observable 的区别
Typical application of "stack" - expression evaluation (implemented in C language)
Which securities company has a low, safe and reliable online account opening commission
材质UV遮罩的技巧
在纽约寻找童真——新泽西州乐高乐园探索中心的美好一天
快速排序基本思路(通俗易懂+例子)「建议收藏」
R语言dplyr包rowwise函数、mutate函数计算dataframe数据中多个数据列在每行的最大值、并生成行最大值对应的数据列(row maximum)
SAP S/4HANA OData Mock Service 介绍
SLC、MLC、TLC 和 QLC NAND SSD 之间的区别:哪个更好?
Tips for material UV masking
任职 22 年,PowerShell 之父将从微软离职:曾因开发 PowerShell 被微软降级过
Nm01 function overview and API definition of nm module independent of bus protocol
元宇宙链游系统开发(逻辑开发)丨链游系统开发(详细分析)
StretchDIBits函数
Excel如何进行隔行复制粘贴
【JVM调优实战100例】03——JVM堆调优四例
Crypto usage in nodejs