zoukankan
html css js c++ java
java8中lambda的用法(map转list,list转map等等)
地址:
https://www.cnblogs.com/tomoto/p/12915049.html
注意List 使用前需要做非空处理
1.以某个属性分组
Map<String,List<User
>> map= userList.stream().collect(Collectors.groupingBy(User::getName));
2.获取集合中的某个属性转为集合
pictureList
.stream()
.map(
Picture::getSrc)
.collect(Collectors.toList());
3.根据集合中的某个属性进行升序重排
roomList
.stream()
.sorted(Comparator.comparing(
Room::getAvgPrice))
.collect(Collectors.toList());
4.根据集合中的某个属性进行降序重排
roomList
.stream()
.sorted(Comparator.comparing(
Room::getAvgPrice).reversed())
.collect(Collectors.toList());
5.集合中的属性去重
rpTags
.stream()
.distinct()
.collect(
Collectors
.toList());
6.根据集合中的某个属性过滤并获取第一个
benefitList
.stream()
.filter(benefit -> benefit.getId() ==
1 || benefit.getId() ==
20 || benefit.getId() ==
26 || benefit.getId() ==
89)
.findFirst()
.orElse(null);
7.根据集合中的属性转换为键值对Map
getModule()
.stream()
.collect(Collectors.toMap(
RateplanDO::getRateplanCode, rateplanDO -> rateplanDO));
8.获取集合中某个最大值的int数据
partnerCityHotelDOList
.stream()
.mapToInt(
PartnerCityHotelDO::getId)
.max()
.orElse(-
1);
9.提取集合中对象的某个属性转化List
partnerCityHotelDOList
.stream()
.map(
PartnerCityHotelDO::getId)
.collect(Collectors.toList());
查看全文
相关阅读:
【郑轻】[1749]Forceast!
【郑轻】[1749]Forceast!
【郑轻】[1754]Chowhound!Chowhound!!Chowhound!!!
【郑轻】[1754]Chowhound!Chowhound!!Chowhound!!!
【郑轻】[1750]Bean!
【郑轻】[1750]Bean!
【郑轻】[1000]整数A+B
【郑轻】[1000]整数A+B
【杭电】[1236]排名
【杭电】[1236]排名
原文地址:https://www.cnblogs.com/mark5/p/13502333.html
最新文章
【CH 4201】楼兰图腾【树状数组】
剪贴板备份在c#
一个多颜色、多字体的检查列表框
在Windows中执行UTF8
ClipSpy +
ClipSpy +
添加一个“选择”选项到一个Windows Forms Databound组合框简单的方法
编码的UI测试技巧4 添加未使用的控件到UI映射
系统驱动浏览器
理解SelectedValue, SelectedValuePath, SelectedItem & DisplayMemberPath + Demo
热门文章
树结构练习——排序二叉树的中序遍历
树结构练习——排序二叉树的中序遍历
哈夫曼C语言代码抄录
哈夫曼C语言代码抄录
数据结构实验之二叉树六:哈夫曼编码
数据结构实验之二叉树六:哈夫曼编码
数据结构实验之二叉树五:层序遍历
数据结构实验之二叉树五:层序遍历
41 复数类的运算符重载
41 复数类的运算符重载
Copyright © 2011-2022 走看看