当前位置:网站首页>When converting from list to map, if a certain attribute may cause key duplication and exceptions, you can set the way to deal with this duplication
When converting from list to map, if a certain attribute may cause key duplication and exceptions, you can set the way to deal with this duplication
2022-07-02 19:07:00 【yuhui66666688gfbfdy】
from list Turn it into map When , According to a certain attribute, it may lead to key Repeated but abnormal , You can set the way to handle this repetition --java8 Of the two, choose one , There are other requirements and other ways to achieve
collect(Collectors.toMap(
Map.Entry::getKey, ---key
Map.Entry::getValue, ---value
(oldVal, newVal) -> oldVal, --- Which one to cover
LinkedHashMap::new --- The object assigned by the new result
)
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
));
边栏推荐
- 新加坡暑假旅游攻略:一天玩转新加坡圣淘沙岛
- reduce--遍历元素计算 具体的计算公式需要传入 结合BigDecimal
- Websocket of Web real-time communication technology
- 第一次去曼谷旅游怎么玩?这份省钱攻略请收好
- Kubernetes three open interfaces first sight
- 【测试开发】软件测试—概念篇
- 2022编译原理期末考试 回忆版
- R language uses lrtest function of epidisplay package to perform likelihood ratio test on multiple GLM models (logisti regression). Compare whether the performance of the two models is different, and
- Stratégie touristique d'été de Singapour: un jour pour visiter l'île de San taosha à Singapour
- Deep learning mathematics foundation
猜你喜欢

The difference between interceptor and filter
![[100 cases of JVM tuning practice] 03 -- four cases of JVM heap tuning](/img/54/8a18cd30e6186528599c0556b1ee3b.png)
[100 cases of JVM tuning practice] 03 -- four cases of JVM heap tuning

Excel如何进行隔行复制粘贴

电商系统中常见的 9 大坑,你踩过没?

High frequency interview questions

Mysql高级篇学习总结7:Mysql数据结构-Hash索引、AVL树、B树、B+树的对比

M2DGR:多源多场景 地面机器人SLAM数据集(ICRA 2022 )

Deep learning mathematics foundation

Processing strategy of message queue message loss and repeated message sending

使用CLion编译OGLPG-9th-Edition源码
随机推荐
FastDFS安装
2022编译原理期末考试 回忆版
UML class diagram
[0701] [论文阅读] Alleviating Data Imbalance Issue with Perturbed Input During Inference
Yesterday, Alibaba senior wrote a responsibility chain model, and there were countless bugs
MySQL advanced learning summary 8: overview of InnoDB data storage structure page, internal structure of page, row format
[100 cases of JVM tuning practice] 01 - introduction of JVM and program counter
R language dplyr package Na_ The if function converts the control in the vector value into the missing value Na, and converts the specified content into the missing value Na according to the mapping r
M2dgr: slam data set of multi-source and multi scene ground robot (ICRA 2022)
Page title component
Mysql高级篇学习总结6:索引的概念及理解、B+树产生过程详解、MyISAM与InnoDB的对比
预处理和预处理宏
Use MNIST in tensorflow 2_ 784 data set for handwritten digit recognition
材质UV遮罩的技巧
R语言ggplot2可视化分面图(facet):gganimate包基于transition_time函数创建动态散点图动画(gif)
[0701] [paper reading] allowing data imbalance issue with perforated input during influence
中国信通院《数据安全产品与服务图谱》,美创科技实现四大板块全覆盖
思维意识转变是施工企业数字化转型成败的关键
【JVM调优实战100例】03——JVM堆调优四例
Obligatoire pour les débutants, cliquez sur deux boutons pour passer à un contenu différent