按條件查詢單個實體類:
User u= user.stream().filter(item ->item.getName().equals(“zs”)).findAny().orElse(null);
按條件篩選多個實體類:
List u= user.stream().filter(item ->item.getName().equals(“zs”)).collect(Collectors.toList());
將list按對象中的某一屬性分組:
Map<String,List<UmoocUserDTO>> collect = list.stream().collect(Collectors.groupingBy(User::getUserNo));
將list聚合成key-對象中的某一屬性,value-對象:
Map<String, UmoocUserDTO> collect = list.stream().collect(Collectors.toMap(User::getUserNo, Function.identity()));
list中對象的某個屬性累加:
Integer total = list.stream().mapToInt(User::getCount).sum();
list中對象的某個屬性聚合成list:
list<Integer> list1 = list.stream().map(t -> t.getRole()).collect(Collectors.toList())
list快速遍歷篩選:
long count = numbers.stream().filter(i->i>20).count();
List<Integer> list1 = list.stream().filter(i->i>50).collect(Collectors.toList());
list中求對象中某個屬性的最大值:
Optional<UmoocUserDTO> max = users.stream().max((p1, p2) -> Integer.compare(p1.getAge(), p2.getAge()));
bigdecimal累計求和:
BigDecimal reduce = list.stream().map(ApAccountBegin::getBeginQuantity).reduce(BigDecimal.ZERO,BigDecimal::add);
篩選list中是否存在符合條件的字段:
boolean hasGrade = betweenList.stream().allMatch(t -> t.getGrade() == null);
