当前位置:网站首页>list转换map(根据key来拆分list,相同key的value为一个list)
list转换map(根据key来拆分list,相同key的value为一个list)
2020-11-06 21:45:00 【会开车的架构师】
/**
* @description 按照key拆分list
* @data ${DATA}
* @auther
*/
public class MyListTOMap {
public static void main(String[] args) {
UserTest user1 = new UserTest(10,"xiaoming");
UserTest user2 = new UserTest(20,"zhongming");
UserTest user3 = new UserTest(30,"daming");
UserTest user4 = new UserTest(30,"i'mgoal");
List<UserTest> list = new ArrayList<>();
list.add(user1);
list.add(user2);
list.add(user3);
list.add(user4);
Map<Integer,List<UserTest>> mapTest = new HashMap<>();
for (UserTest u: list) {
if(mapTest.containsKey(u.getAge())){
mapTest.get(u.getAge()).add(u);
}else{
List<UserTest> tempList = new ArrayList<>();
tempList.add(u);
mapTest.put(u.getAge(),tempList);
}
}
list.forEach(System.out::println);
System.out.println(mapTest);
}
}
版权声明
本文为[会开车的架构师]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/4629483/blog/4529695
边栏推荐
- 代码生成器插件与Creator预制体文件解析
- C + + and C + + programmers are about to be eliminated from the market
- Read the advantages of Wi Fi 6 over Wi Fi 5 in 3 minutes
- 【ElasticSearch搜索引擎】
- Asp.Net Core learning notes: Introduction
- ES6 learning notes (2): teach you to play with class inheritance and class objects
- What is the meaning of sector sealing of filecoin mining machine since the main network of filecoin was put online
- MongoDB与SQL常用语法对应表
- 游戏开发中的新手引导与事件管理系统
- jenkins安装部署过程简记
猜你喜欢

Take you to learn the new methods in Es5

Flink's datasource Trilogy 2: built in connector

嘉宾专访|2020 PostgreSQL亚洲大会阿里云数据库专场:曾文旌

image operating system windows cannot be used on this platform
![Network security engineer Demo: the original * * is to get your computer administrator rights! [maintain]](/img/14/ede1ffa7811dbc2a5b15b9a7b17a5e.jpg)
Network security engineer Demo: the original * * is to get your computer administrator rights! [maintain]
![Tron smart wallet PHP development kit [zero TRX collection]](/img/3b/00bc81122d330c9d59909994e61027.jpg)
Tron smart wallet PHP development kit [zero TRX collection]

GUI engine evaluation index

ado.net和asp.net的关系

事务的本质和死锁的原理

Kubernetes and OAM to build a unified, standardized application management platform knowledge! (Internet disk link attached)
随机推荐
What if the front end doesn't use spa? - Hacker News
nacos、ribbon和feign的簡明教程
Try to build my mall from scratch (2): use JWT to protect our information security and perfect swagger configuration
Introduction to Google software testing
Staying up late summarizes the key points of report automation, data visualization and mining, which is different from what you think
Get twice the result with half the effort: automation without cabinet
For a while, a dynamic thread pool was created, and the source code was put into GitHub
大数据处理黑科技:揭秘PB级数仓GaussDB(DWS) 并行计算技术
From overseas to China, rancher wants to do research on container cloud market
(2) ASP.NET Core3.1 Ocelot routing
C#和C/C++混合编程系列5-内存管理之GC协同
Some operations kept in mind by the front end foundation GitHub warehouse management
【自学unity2d传奇游戏开发】地图编辑器
ES6 learning notes (5): easy to understand ES6's built-in extension objects
C# 调用SendMessage刷新任务栏图标(强制结束时图标未消失)
An article takes you to understand CSS pagination examples
How does filecoin's economic model and future value support the price of fil currency breaking through thousands
Humor: hacker programming is actually similar to machine learning!
Xmppmini project details: step by step from the principle of practical XMPP technology development 4. String decoding secrets and message package
In depth to uncover the bottom layer of garbage collection, this time let you understand her thoroughly