当前位置:网站首页>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
));
边栏推荐
- 彻底搞懂基于Open3D的点云处理教程!
- R语言dplyr包rowwise函数、mutate函数计算dataframe数据中多个数据列在每行的最大值、并生成行最大值对应的数据列(row maximum)
- Leetcode (81) -- search rotation sort array II
- 电商系统中常见的 9 大坑,你踩过没?
- C的内存管理
- Page title component
- Industrial software lecture - core technology analysis of 3D CAD design software - the second lecture of the Forum
- Crypto usage in nodejs
- How to play when you travel to Bangkok for the first time? Please keep this money saving strategy
- 【每日一题】第二天
猜你喜欢

Mysql高级篇学习总结8:InnoDB数据存储结构页的概述、页的内部结构、行格式
![[daily question] the next day](/img/8a/18329bd9b4a3a4445c8fbbc1ce562b.png)
[daily question] the next day

ICDE 2023|TKDE Poster Session(CFP)

仿京东放大镜效果(pink老师版)

ICDE 2023|TKDE Poster Session(CFP)
![[100 cases of JVM tuning practice] 02 - five cases of virtual machine stack and local method stack tuning](/img/59/6c776e0607a52962b72fbea2e64c8e.png)
[100 cases of JVM tuning practice] 02 - five cases of virtual machine stack and local method stack tuning

The text editor hopes to mark the wrong sentences in red, and the text editor uses markdown

材质UV遮罩的技巧

使用 Cheat Engine 修改 Kingdom Rush 中的金钱、生命、星

新加坡暑假旅遊攻略:一天玩轉新加坡聖淘沙島
随机推荐
【JVM调优实战100例】03——JVM堆调优四例
二进制操作
新加坡暑假旅游攻略:一天玩转新加坡圣淘沙岛
性能测试如何创造业务价值
Learn the knowledge points of eight part essay ~ ~ 1
Talk about the design of red envelope activities in e-commerce system
Yesterday, Alibaba senior wrote a responsibility chain model, and there were countless bugs
SQL training 2
[0701] [paper reading] allowing data imbalance issue with perforated input during influence
Leetcode (81) -- search rotation sort array II
9D电影是怎样的?(+维度空间常识)
Fastdfs installation
Hongmeng's fourth learning
Use MNIST in tensorflow 2_ 784 data set for handwritten digit recognition
R语言使用epiDisplay包的cox.display函数获取cox回归模型汇总统计信息(风险率HR、调整风险率及其置信区间、模型系数的t检验的p值、Wald检验的p值和似然比检验的p值)、汇总统计
FastDFS安装
深度学习数学基础
Hospital online inquiry source code hospital video inquiry source code hospital applet source code
The second bullet of AI development and debugging series: the exploration journey of multi machine distributed debugging
Leetcode (154) -- find the minimum value II in the rotation sort array