java 8 lambda表达式list操作分组、过滤、求和、最值、排序、去重

https://blog.csdn.net/u014231523/article/details/102535902

//1.提取出list对象中的一个属性
List<String> stIdList1 = stuList.stream().map(Person::getId).collect(Collectors.toList());

//2.提取出list对象中的一个属性并去重
List<String> stIdList2 = stuList.stream().map(Person::getId).distinct().collect(Collectors.toList());

//从一个Person对象的List集合,取出id和name组成一个map集合
Map<String, String> collect = list.stream().collect(Collectors.toMap(p -> p.getId(), p -> p.getName(),(oldValue, newValue)->newValue));
Map<String, Person> collect = list.stream().collect(Collectors.toMap(p -> p.getId(), p -> p));

//过滤
List<Person> filterList = persons.stream().filter(p -> p.getSex().equals(1)).collect(Collectors.toList());

//分组
Map<String, Long> collect = dogs.stream().collect(Collectors.groupingBy(i -> i.getName(), Collectors.counting()));

https://blog.csdn.net/zzqcsdn123/article/details/106871884

https://blog.csdn.net/gsls200808/article/details/86501905

https://developer.ibm.com/zh/articles/j-lo-java8streamapi/

http://www.shixinke.com/date-2019-10.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值