当前位置:网站首页>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
));
边栏推荐
- What is 9D movie like? (+ common sense of dimension space)
- 2022编译原理期末考试 回忆版
- How to enable the run dashboard function of idea
- Tips for material UV masking
- [fluent] dart data type (VaR data type | object data type)
- 产品经理应具备的能力
- 2022软件工程期末考试 回忆版
- ORA-01455: converting column overflows integer datatype
- 使用 Cheat Engine 修改 Kingdom Rush 中的金钱、生命、星
- Installation of thingsboard, an open source IOT platform
猜你喜欢

How can retail enterprises open the second growth curve under the full link digital transformation

Yolov3 trains its own data set to generate train txt
![[daily question] the next day](/img/8a/18329bd9b4a3a4445c8fbbc1ce562b.png)
[daily question] the next day

How performance testing creates business value
![[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

9D电影是怎样的?(+维度空间常识)

彻底搞懂基于Open3D的点云处理教程!

PyTorch函数中的__call__和forward函数

STM32G0 USB DFU 升级校验出错-2
![[fluent] dart data type (VaR data type | object data type)](/img/1b/fe2529af5f6663fad1fb7861f14ab5.jpg)
[fluent] dart data type (VaR data type | object data type)
随机推荐
FastDFS安装
How to enable the run dashboard function of idea
Compile oglpg-9th-edition source code with clion
Tips for material UV masking
Use MNIST in tensorflow 2_ 784 data set for handwritten digit recognition
#gStore-weekly | gStore源码解析(四):安全机制之黑白名单配置解析
R语言使用epiDisplay包的cox.display函数获取cox回归模型汇总统计信息(风险率HR、调整风险率及其置信区间、模型系数的t检验的p值、Wald检验的p值和似然比检验的p值)、汇总统计
Troubleshooting: kubectl reports an error validationerror: unknown field \u00a0
M2DGR:多源多场景 地面机器人SLAM数据集(ICRA 2022 )
Gstore weekly gstore source code analysis (4): black and white list configuration analysis of security mechanism
Golang并发编程——goroutine、channel、sync
全链路数字化转型下,零售企业如何打开第二增长曲线
SLC、MLC、TLC 和 QLC NAND SSD 之间的区别:哪个更好?
Leetcode (81) -- search rotation sort array II
【JVM调优实战100例】03——JVM堆调优四例
Singapore summer tourism strategy: play Singapore Sentosa Island in one day
C文件输入操作
[test development] takes you to know what software testing is
The difference between SLC, MLC, TLC and QLC NAND SSD: which is better?
中国信通院《数据安全产品与服务图谱》,美创科技实现四大板块全覆盖