java8 新特性 持续更新

q松_松q

关注

阅读 160

2022-11-19

对list中某个对象的属性求和

BigDecimal money = userList.stream().map(User::getInvoiceMoney).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);

分组

Map<String,List<User>> listMap = userList.stream().collect(Collectors.groupingBy(User::getBusinessType));

map的遍历

for (Map.Entry<String,List<User>> entry : listMap.entrySet()) {
String businessType = entry.getKey();
List<User> userList= entry.getValue();
}

filter 过滤

userList.stream().filter(s -> s.getIsDefault() || s.getFirstAccount()).findFirst().orElse(null);

精彩评论(0)

0 0 举报