一、Stream流
1.將某個集合中的金額字段相加
Bigdecimal amount = list.stream().map(TransInfoEntity::getAmount).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
2.將集合中某兩個字段組合成一個map
Map<Long, String> map = list.stream().collect(Collectors.toMap(Student::getId, Student::getName));
3.對集合中某個字段進行過濾如果字段中前兩個字是美團的話就取出來。
List<TransInfo> collect1 = list.stream().filter(s -> Constants.MT_ZFC.equals(s.getDigest().substring(0, 2))).collect(Collectors.toList());
4. 取出集合中的某個字段組成一個新的集合
List<Long> collect = sysUserEntities1.stream().map(SysUserEntity::getOrgId).distinct().collect(Collectors.toList());
5.對集合中某個字段進行排序
voList.stream().sorted(Comparator.comparing(CoordinateVo::getX, String.CASE_INSENSITIVE_ORDER)).collect(Collectors.toList());
點贊加關注,持續更新中!!!