- 将couponList集合中的CouponVo对象里的属性couponId,去重并转换成字符串。
(1)去重:.distinct()
(2)转换成字符串:.collect(Collectors.joining(“,”))
String couponId = couponList.stream().map(CouponVo::getCouponId).distinct().collect(Collectors.joining(","));
- 将payList集合中的RechargePayItem对象里的属性amount,求和并且类型为INT。
(1)求和:.sum()
(2)Int类型:.mapToInt(RechargePayItem::getAmount)
Integer total = payList.stream().mapToInt(RechargePayItem::getAmount).sum();
- 将couponList集合中的CouponVo对象里的符合条件(couponNumber不为空),组成新的List集合。
(1)条件筛选:.filter(item->null != item.getCouponNumber())
(2)添加到新List:.collect(Collectors.toList())
List<CouponVo> couponNumberNotNullList = couponList.stream().filter(item->null != item.getCouponNumber()).collect(Collectors.toList());
- 将listPerson集合中符合条件的数据组装成需要的字符串
for (RechargeOrderDetail item: pageList) {
String sellVipPersonJSON = listPerson.stream()
.filter(person -> item.getPaymentId().equals(person.getPaymentId()))
.map(person->{
return StrUtil.isNotBlank(person.getSellJobNum()) && !"0".equals(person.getSellJobNum())
?"("+person.getSellJobNum()+")"+person.getSellName()
:(StrUtil.isNotBlank(person.getSellName())?person.getSellName():null);
})
.collect(Collectors.joining(","));
item.setSellVipPerson(sellVipPersonJSON);
}
- 将payItemList集合中的RechargePayItem对象里的属性payType,去重并计算个数。
(1)去重:.distinct()
(2)个数:.count()
long listSize = payItemList.stream().map(RechargePayItem::getPayType).distinct().count();
- 将pageList集合中的WorkNextConfig对象里的属性next,进行分组并转换成字符串。
(1)分组:.collect(Collectors.groupingBy(p -> p.getNext(), Collectors.toList()))
Map<String, List<WorkNextConfig>> collect = pageList.stream().collect(Collectors.groupingBy(p -> p.getNext(), Collectors.toList()));
collect.forEach((key, value) -> {
WorkNextConfig workNextConfig = new WorkNextConfig();
String department =value.stream().map(item->String.valueOf(item.getOrgid())).collect(Collectors.joining(","));
workNextConfig.setDepartment(department);
});
- 将dataList集合中的WorkTaskContent对象里的属性fgrade不为空,则进行求和
(1)条件:.filter(w->null != w.getFgrade())
(2)计算分值:.map(w -> w.getWeight().multiply(w.getFgrade()).divide(new BigDecimal(100)))
(3)求和:.reduce(BigDecimal.ZERO,BigDecimal::add)
BigDecimal fgradeTotal = dataList.stream().filter(w->null != w.getFgrade()).map(w -> w.getWeight().multiply(w.getFgrade()).divide(new BigDecimal(100))).reduce(BigDecimal.ZERO,BigDecimal::add);