对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);