本文主要是介绍java8中lambda的用法(map转list,list转map等等,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
注意List 使用前需要做非空处理
Map<String,List<User>> map= userList.stream().collect(Collectors.groupingBy(User::getName));
pictureList.stream().map(Picture::getSrc).collect(Collectors.toList());
roomList.stream().sorted(Comparator.comparing(Room::getAvgPrice)).collect(Collectors.toList());
roomList.stream().sorted(Comparator.comparing(Room::getAvgPrice).reversed()).collect(Collectors.toList());
rpTags.stream().distinct().collect(Collectors.toList());
benefitList.stream().filter(benefit -> benefit.getId() == 1 || benefit.getId() == 20 || benefit.getId() == 26 || benefit.getId() == 89) .findFirst().orElse(null);
getModule().stream().collect(Collectors.toMap(RateplanDO::getRateplanCode, rateplanDO -> rateplanDO));
partnerCityHotelDOList.stream().mapToInt(PartnerCityHotelDO::getId).max().orElse(-1);
partnerCityHotelDOList.stream().map(PartnerCityHotelDO::getId).collect(Collectors.toList());
这篇关于java8中lambda的用法(map转list,list转map等等的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!