java8 lambda python_Java8 lambda表达式收集汇总

1 有一个对象列表,根据对象中某个字段对列表进行分组,分组后获取组中对象列表中某个字段最大的值:

customerList.stream().filter(customer -> null != customer.getCreateDate())

.collect(Collectors.groupingBy(cn.com.servyou.xqy.gaia.facade.customer.dto.DzbCustomerDTO::getCustomerId,

Collectors.collectingAndThen(Collectors.mapping(cn.com.servyou.xqy.gaia.facade.customer.dto.DzbCustomerDTO::getCreateDate, Collectors.toSet()), set ->

set.stream().max(Date::compareTo).orElse(null))));

2 有一个对象列表,根据对象中某个字段对对象列表进行分组,分组后对每组对象中的某个字段求和

Map customerIdPrintNumMap = printResult.stream().collect(Collectors.groupingBy(CustomerFinanceInfoPrintRecordDTO::getCustomerId, Collectors

.collectingAndThen(Collectors.mapping(CustomerFinanceInfoPrintRecordDTO::getPrintNum, Collectors.toList()), list ->

list.stream().mapToInt(Integer::intValue).sum()

有一个对象列表,根据对象中某个字段对对象列表进行分组,对组内对象列表根据对象某个字段在组内排序后取最小的对象

Map dzbCustomerMap = dzbWebCustomerBossRelationshipFacadeClient.queryByCustomerIdList(companyId, customerIdList).stream().filter(a -> StringUtils.isNotBlank(a.getCustomerId()))

.collect(Collectors.groupingBy(DzbWebCustomerBossRelationshipDTO::getCustomerId, Collectors.collectingAndThen(Collectors.toList(),

list -> list.stream().min(Comparator.comparing(DzbWebCustomerBossRelationshipDTO::getCreateDate)).orElse(null))));```

代码块

代码块

代码块

代码块

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值