当前位置:网站首页>How to classify the same field values in a list under the same list
How to classify the same field values in a list under the same list
2022-07-23 10:08:00 【Know the world through practice】
Method 1
List<List<User>> result = new ArrayList<>();
Map<Integer,List<User>> map = new HashMap<>();
//userList To operate list aggregate
for (User user : userList) {
Integer age = user.getAge();
List<User > lstUser;
if (map.containsKey(age)) {
lstUser= map.get(age);
}else{
lstUser= new ArrayList<>();
}
lstUser.add(user);
map.put(age,lstUser);
}
for (Map.Entry<Integer, List<User>> entry : map.entrySet()) {
result.add(entry.getValue());
}
Method 2
List<List<AirTimeRangeContract>> result = new ArrayList<List<AirTimeRangeContract>>();
Map<Long, List<AirTimeRangeContract>> map = new TreeMap<Long, List<AirTimeRangeContract>>();
for (AirTimeRangeCon边栏推荐
- 拓扑排序 & 关键路径
- How is it safe to open an account for Haitong Securities' exchange fund
- 完成端口的几个重要问题
- [node middle tier practice (III)] --- template engine Pug
- This is how the permission system is designed, yyds
- 【HiFlow】定期发送腾讯云短信发送群
- PHP 脚本对 txt 内容进行分页案例
- The gospel of small and medium-sized enterprises is coming! Jnpf is becoming popular, helping business digital upgrading
- 141.环形链表
- 用现代化的开发方法和思维,打跑遗留系统“拦路虎”
猜你喜欢

567. 字符串的排列

十年磨一剑,云原生分布式数据库PolarDB-X的核心技术演化

Qt报错:错误 C2039 “Value“: 不是 “`global namespace‘“ 的成员

Fireshare for short video sharing

Baidu map eagle eye track service

Seven sorts -- detailed explanation of ten thousand words

C language flexible array

non-Boost Asio 笔记: UDP UART SocketCAN Multicast UDS

适合短视频分享的Fireshare

141.环形链表
随机推荐
Ten years of sharpening a sword, the core technology evolution of the cloud native distributed database polardb-x
BGP反射器,联邦,选路规则
redis分片集群如何搭建与使用
笔记——记录@RefreshScope动态刷新配置失效的解决方式
解密 Redis 助力双 11 背后电商秒杀系统
九张图纵观加密市场周期规律
Airtest脚本的点击位置与点击偏移
Baidu map eagle eye track service
PHP converts pictures to Base64 format and restores them to generate pictures
七大排序--万字详解
笔记——记录一个dynamic-datasource please check the setting of primary 问题解决
线性代数之二阶与三阶行业式
Visual full link log tracking
60 open-ended test questions, recite them and get a pay rise directly
【Node中间层实践(三)】----模板引擎pug
Seven sorts -- detailed explanation of ten thousand words
范式及反范式
Liunx上杀死一进程
隐藏网站服务器响应头中 PHP 版本信息
【HiFlow】定期发送腾讯云短信发送群