当前位置:网站首页>List to map (split the list according to the key, and the value of the same key is a list)
List to map (split the list according to the key, and the value of the same key is a list)
2020-11-06 21:45:00 【Architects who can drive】
/**
* @description according to key Split 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);
}
}
版权声明
本文为[Architects who can drive]所创,转载请带上原文链接,感谢
边栏推荐
- [byte jumps, autumn recruitment Posts open] ohayoo! Don't leave after school, I want to ask you to play games!!!
- Open source a set of minimalist front and rear end separation project scaffold
- 2020-09-03:裸写算法:回形矩阵遍历。
- 实用工具类函数(持续更新)
- JVM memory allocation - xms128m - xmx512m - XX: permsize = 128M - XX: maxpermsize = 512M
- 2020-08-29:进程线程的区别,除了包含关系之外的一些区别,底层详细信息?
- How to play sortable JS vuedraggable to realize nested drag function of forms
- 小熊派开发板实践:智慧路灯沙箱实验之真实设备接入
- Using iceberg on kubernetes to create a new generation of cloud original data Lake
- What the hell is fastthreadlocal? The existence of ThreadLocal!!
猜你喜欢
C calls SendMessage to refresh the taskbar icon (the icon does not disappear at the end of forcing)
Js字符串-String字符串对象方法
To Lianyun analysis: why is IPFs / filecoin mining so difficult?
list转换map(根据key来拆分list,相同key的value为一个list)
This project allows you to quickly learn about a programming language in a few minutes
[elastic search engine]
行为型模式之备忘录模式
A small goal in 2019 to become a blog expert of CSDN
With this artifact, quickly say goodbye to spam messages
Some operations kept in mind by the front end foundation GitHub warehouse management
随机推荐
1万辆!理想汽车召回全部缺陷车:已发生事故97起,亏损将扩大
Zero basis to build a web search engine of its own
Interviewer: how about shardingsphere
Visual rolling [contrast beauty]
行为型模式之解释器模式
An article will take you to understand CSS3 fillet knowledge
Python basic variable type -- list analysis
Some operations kept in mind by the front end foundation GitHub warehouse management
意派Epub360丨你想要的H5模板都在这里,电子书、大转盘、红包雨、问卷调查……
win7 APPCRASH(解决方法)(转)
Metersphere developer's Manual
Axios learning notes (2): easy to understand the use of XHR and how to package simple Axios
谷歌浏览器实现视频播放加速功能
Introduction to the development of small game cloud
2020-08-24:什么是小文件?很多小文件会有什么问题?很多小文件怎么解决?(大数据)
What is the tensor in tensorflow?
Unity performance optimization
Contract trading system development | construction of smart contract trading platform
Elasticsearch database | elasticsearch-7.5.0 application construction
Those who have worked in China for six years and a million annual salary want to share these four points with you