zoukankan
html css js c++ java
java8中lambda的用法(map转list,list转map等等
注意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());
查看全文
相关阅读:
程序是怎样跑起来的 第三章
C#4.5-4.7学习总结
第二周学习总结
程序是如何跑起来的 第二章
第一章读后感
师生关系读后感
C#学习总结
我与计算机
读《程序怎样跑起来》第一章有感
读师生关系有感
原文地址:https://www.cnblogs.com/xiaoxiao1120/p/15641558.html
最新文章
《程序是怎样跑起来的》第八章读后感
《程序是怎样跑起来的》第七章读后感
《程序是怎样跑起来的》第六章读后感
《程序是怎样跑起来的》第五章读后感
《程序是怎样跑起来的》第四章读后感
《程序是怎样跑起来的》第三章读后感
《程序是怎样跑起来的》第二章读后感
《程序是怎样跑起来的》第一章读后感
大学师生关系读后感
我与计算机
热门文章
第四周学习总结
《程序是怎样跑起来的》第六章
第三周学习总结
第二周学习总结
《程序是怎样跑起来的》第五章
《程序是怎样跑起来的》第四章
《程序是怎样跑起来的》第三章
《程序是怎样跑起来的》第二章
《程序是怎样跑起来的》第一章读后感
大学师生关系读后感
Copyright © 2011-2022 走看看