当前位置:网站首页>从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
));
边栏推荐
- 医院在线问诊源码 医院视频问诊源码 医院小程序源码
- CDN acceleration and breaking J anti-theft chain function
- Which securities company has a low, safe and reliable online account opening commission
- 任职 22 年,PowerShell 之父将从微软离职:曾因开发 PowerShell 被微软降级过
- 300+ documents! This article explains the latest progress of multimodal learning based on transformer
- UE4 用spline畫正圓
- Meta universe chain game system development (logic development) - chain game system development (detailed analysis)
- The second bullet of AI development and debugging series: the exploration journey of multi machine distributed debugging
- Three ways of function parameter transfer in C language
- The student Tiktok publicized that his alma mater was roast about "reducing the seal of enrollment". Netizen: hahahahahahahaha
猜你喜欢

Responses of different people in technology companies to bugs | daily anecdotes

Excel如何进行隔行复制粘贴

Tips for material UV masking

STM32G0 USB DFU 升级校验出错-2

Yesterday, Alibaba senior wrote a responsibility chain model, and there were countless bugs

材质UV遮罩的技巧

工业软件讲堂-三维CAD设计软件的核心技术解析----讲坛第二次讲座

SLC、MLC、TLC 和 QLC NAND SSD 之间的区别:哪个更好?

Leetcode(81)——搜索旋转排序数组 II

什么是云原生?这回终于能搞明白了!
随机推荐
Excel如何进行隔行复制粘贴
PR曲线和ROC曲线概念及其区别
学习八股文的知识点~~1
[Yugong series] July 2022 go teaching course 001 introduction to go language premise
iptable端口重定向 MASQUERADE[通俗易懂]
M2DGR:多源多场景 地面机器人SLAM数据集(ICRA 2022 )
M2dgr: slam data set of multi-source and multi scene ground robot (ICRA 2022)
Basic idea of quick sorting (easy to understand + examples) "suggestions collection"
科技公司不同人对Bug的反应 | 每日趣闻
故障排查:kubectl报错ValidationError: unknown field \u00a0
R语言dplyr包na_if函数把向量数值中的控制转化为缺失值NA、按照映射规则把指定内容转化为缺失值NA
Deep learning mathematics foundation
什么是云原生?这回终于能搞明白了!
R language ggplot2 visualization: visualize the line chart and add customized X-axis label information to the line chart using labs function
Leetcode interview question 17.01 Addition without plus sign
[daily question] first day
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
Crypto usage in nodejs
SAP S/4HANA OData Mock Service 介绍
R语言ggplot2可视化:可视化折线图、使用labs函数为折线图添加自定义的X轴标签信息