当前位置:网站首页>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
));
边栏推荐
- 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
- How to play when you travel to Bangkok for the first time? Please keep this money saving strategy
- 在Tensorflow2中使用mnist_784数据集进行手写数字识别
- The difference between SLC, MLC, TLC and QLC NAND SSD: which is better?
- 使用 Cheat Engine 修改 Kingdom Rush 中的金钱、生命、星
- The difference between promise and observable
- R语言ggplot2可视化:可视化折线图、使用labs函数为折线图添加自定义的X轴标签信息
- 【测试开发】一文带你了解什么是软件测试
- Exness in-depth good article: dynamic series - Case Analysis of gold liquidity (V)
- 预处理和预处理宏
猜你喜欢
[100 cases of JVM tuning practice] 03 -- four cases of JVM heap tuning
CDN acceleration and breaking J anti-theft chain function
Redis (6) -- object and data structure
Kubernetes three open interfaces first sight
Comprendre complètement le tutoriel de traitement de Point Cloud basé sur open3d!
性能测试如何创造业务价值
The text editor hopes to mark the wrong sentences in red, and the text editor uses markdown
[100 cases of JVM tuning practice] 01 - introduction of JVM and program counter
The difference between interceptor and filter
How to copy and paste interlaced in Excel
随机推荐
The difference between SLC, MLC, TLC and QLC NAND SSD: which is better?
Industrial software lecture - core technology analysis of 3D CAD design software - the second lecture of the Forum
[fluent] dart data type (VaR data type | object data type)
Progress progress bar
Compile oglpg-9th-edition source code with clion
Exness in-depth good article: dynamic series - Case Analysis of gold liquidity (V)
UML 类图
在纽约寻找童真——新泽西州乐高乐园探索中心的美好一天
[test development] software testing - concept
Mini Golf Course: a good place for leisure and tourism in London
仿京东放大镜效果(pink老师版)
How performance testing creates business value
MySQL advanced learning summary 7: MySQL data structure - Comparison of hash index, AVL tree, B tree and b+ tree
新手必看,點擊兩個按鈕切換至不同的內容
【每日一题】第二天
Introduction to the paper | application of machine learning in database cardinality estimation
中国信通院《数据安全产品与服务图谱》,美创科技实现四大板块全覆盖
论文导读 | 关于将预训练语言模型作为知识库的分析与批评
《病人家属,请来一下》读书笔记
Novice must see, click two buttons to switch to different content