当前位置:网站首页>Group before getting the maximum value in stream operation
Group before getting the maximum value in stream operation
2022-07-23 09:16:00 【Kuo-Teng】
Group by an attribute , And take the maximum according to another attribute
A list of students , From multiple classes , There are several students in each class ; Take out the oldest student in each class , Form a new list ;
return new ArrayList<>(studentList.stream()
.collect(Collectors.toMap(Student::getClassId, Function.identity(),
(c1, c2) -> c1.getAge() > c2.getAge() ? c1 : c2))
.values());
- First, turn to Map, In class ID by key, The oldest in the class Student The object is value;
- Take out the Map Of values;
- Plug into the ArrayList And in return ;
边栏推荐
猜你喜欢

Compose与RecyclerView结合效果会是怎样的?

Internet download manager is simply a killer of downloaders

【MySQL从入门到精通】【高级篇】(七)设计一个索引&InnoDB中的索引方案

C语言经典练习题(1)——“水仙花数“

SPSS Chi-Square

Summary of some open source libraries that drive MCU hardware debugger (including stlink debugger)
How many points can you get on the latest UnionPay written test for test engineers?

AirServer第三方投屏软件v7.3.0中文版 (Airplay终端实用工具)

BGP機房的優點

超全PMP备考文档汇总
随机推荐
C语言实战之猜数游戏
Pytorch simple sample summary
FasterRCNN示例代码测试1:令anchor_generator = None
Const char* in vs2022 cannot assign char*
SQL用户表的通用设计
【Try to Hack】AWVS安装和简单使用
推荐系统专题 | 推荐系统架构与单域跨域召回模型
Regular expression conversion to corresponding text gadget
Mathematical modeling -- graph and network models and methods (II)
AirServer第三方投屏软件v7.3.0中文版 (Airplay终端实用工具)
程序员必须掌握的600个英语单词
如何高效系统学习 MySQL?
【并发编程】第二章:从核心源码深入ReentrantLock锁
[wechat applet] Introduction to development (2)
UGUI源码解析——MaskUtilities
transformer汇总
Development of ordering system in epidemic isolation area
程序员不会 jvm?骨灰级工程师:全等着被淘汰吧!这是必会技能!
SPSS Chi-Square
一文了解微服务低代码实现方式