当前位置:网站首页>从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
));
边栏推荐
- 科技公司不同人对Bug的反应 | 每日趣闻
- Troubleshooting: kubectl reports an error validationerror: unknown field \u00a0
- Redis(6)----对象与数据结构
- 【每日一题】第二天
- 深度神经网络总结
- STM32G0 USB DFU 升级校验出错-2
- Which securities company has a low, safe and reliable online account opening commission
- SAP S/4HANA OData Mock Service 介绍
- UML 类图
- 300+ documents! This article explains the latest progress of multimodal learning based on transformer
猜你喜欢
Mini Golf Course: a good place for leisure and tourism in London
【每日一题】第一天
新加坡暑假旅游攻略:一天玩转新加坡圣淘沙岛
The student Tiktok publicized that his alma mater was roast about "reducing the seal of enrollment". Netizen: hahahahahahahaha
Redis (7) -- database and expiration key
医院在线问诊源码 医院视频问诊源码 医院小程序源码
夜神模擬器+Fiddler抓包測試App
UE4 draw a circle with spline
Singapore summer tourism strategy: play Singapore Sentosa Island in one day
什么是云原生?这回终于能搞明白了!
随机推荐
在纽约寻找童真——新泽西州乐高乐园探索中心的美好一天
Stretchdibits function
【JVM调优实战100例】02——虚拟机栈与本地方法栈调优五例
Which securities company has a low, safe and reliable online account opening commission
Responses of different people in technology companies to bugs | daily anecdotes
R language uses the lsnofunction function function of epidisplay package to list all objects in the current space, except user-defined function objects
消除IBM P750小机上的黄色报警灯[通俗易懂]
[daily question] first day
Stratégie touristique d'été de Singapour: un jour pour visiter l'île de San taosha à Singapour
R language ggplot2 visual Facet: gganimate package is based on Transition_ Time function to create dynamic scatter animation (GIF)
如何设置VSCode删除整行快捷键?
The R language dplyr package rowwise function and mutate function calculate the maximum value of multiple data columns in each row in the dataframe data, and generate the data column (row maximum) cor
@Component cannot get Dao layer
Mysql高级篇学习总结6:索引的概念及理解、B+树产生过程详解、MyISAM与InnoDB的对比
SLAM|如何时间戳对齐?
options should NOT have additional properties
什么是云原生?这回终于能搞明白了!
Redis(6)----对象与数据结构
Meal card hdu2546
IPtable port redirection masquerade[easy to understand]