当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- Unexpected element.. required element
- 【涂鸦物联网足迹】物联网基础介绍篇
- Pn8162 20W PD fast charging chip, PD fast charging charger scheme
- 2020-08-14:数据任务的执行引擎用的哪些?
- A concise tutorial for Nacos, ribbon and feign
- C calls SendMessage to refresh the taskbar icon (the icon does not disappear at the end of forcing)
- 统计项目代码行数
- Bitcoin once exceeded 14000 US dollars and is about to face the test of the US election
- win7 APPCRASH(解决方法)(转)
- ORA-02292: 违反完整约束条件 (MIDBJDEV2.SYS_C0020757) - 已找到子记录
猜你喜欢

GitHub: the foundation of the front end

2020-08-14:数据任务的执行引擎用的哪些?

2020-09-04:函数调用约定了解么?

ado.net and asp.net The relationship between

ES6 learning notes (4): easy to understand the new grammar of ES6

小熊派开发板实践:智慧路灯沙箱实验之真实设备接入

Junit测试出现 empty test suite

Metersphere developer's Manual

ES6 learning notes (2): teach you to play with class inheritance and class objects

Summary of front-end performance optimization that every front-end engineer should understand:
随机推荐
Epu360: all the H5 templates you want are here, e-book, big turntable, red envelope rain, questionnaire survey
An article will take you to understand CSS alignment
This project allows you to quickly learn about a programming language in a few minutes
行为型模式之解释器模式
2020-09-09:裸写算法:两个线程轮流打印数字1-100。
Git rebase is in trouble. What to do? Waiting line
C calls SendMessage to refresh the taskbar icon (the icon does not disappear at the end of forcing)
How about small and medium-sized enterprises choose shared office?
实用工具类函数(持续更新)
win7 APPCRASH(解决方法)(转)
Elasticsearch database | elasticsearch-7.5.0 application construction
【涂鸦物联网足迹】涂鸦云平台全景介绍
ado.net and asp.net The relationship between
html+ vue.js Implementing paging compatible IE
What kind of music do you need to make for a complete game?
JVM memory allocation - xms128m - xmx512m - XX: permsize = 128M - XX: maxpermsize = 512M
A concise tutorial for Nacos, ribbon and feign
How to start the hidden preferences in coda 2 on the terminal?
Qt音视频开发46-视频传输UDP版
Event monitoring problem