当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- How does filecoin's economic model and future value support the price of fil currency breaking through thousands
- Es create a new index database and copy the old index library, practice pro test effective!
- C calls SendMessage to refresh the taskbar icon (the icon does not disappear at the end of forcing)
- 事务的本质和死锁的原理
- Unexpected element.. required element
- Axios learning notes (2): easy to understand the use of XHR and how to package simple Axios
- ES6 learning notes (4): easy to understand the new grammar of ES6
- Application insights application insights use application maps to build request link views
- Git rebase is in trouble. What to do? Waiting line
- Detect certificate expiration script
猜你喜欢

消防器材RFID固定资产管理系统

Contract trading system development | construction of smart contract trading platform

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

2020-08-19:TCP是通过什么机制保障可靠性的?

Introduction to Huawei cloud micro certification examination

2020-09-03:裸写算法:回形矩阵遍历。

An article takes you to understand CSS pagination examples

Why is quicksort so fast?

Code generator plug-in and creator preform file analysis

2020-08-14:数据任务的执行引擎用的哪些?
随机推荐
What are the highlights of Huawei mate 40 series with HMS?
Using iceberg on kubernetes to create a new generation of cloud original data Lake
What the hell is fastthreadlocal? The existence of ThreadLocal!!
A small goal in 2019 to become a blog expert of CSDN
Nodejs中使用jsonwebtoken(JWT)生成token的场景使用
嘉宾专访|2020 PostgreSQL亚洲大会阿里云数据库专场:曾文旌
2020-08-14:数据任务的执行引擎用的哪些?
实用工具类函数(持续更新)
迅为-iMX6ULL开发板上配置AP热点
What grammar is it? ]
2020-08-29:进程线程的区别,除了包含关系之外的一些区别,底层详细信息?
win7 APPCRASH(解决方法)(转)
File download manager realized by electron
Interviewer: how about shardingsphere
[learning] interface test case writing and testing concerns
What is the tensor in tensorflow?
细数软件工程----各阶段必不可少的那些图
【涂鸦物联网足迹】物联网基础介绍篇
轻量型 GPU 应用首选 京东智联云推出 NVIDIA vGPU 实例
Common mathematical basic formulas of recursive and backtracking algorithms