分组
Map<String, List<Student>> collect = stuList.stream().collect(Collectors.groupingBy(Student::getClassId));
for(Map.Entry<String, List<Student>> stuMap:collect.entrySet()){
String classId = stuMap.getKey();
List<Student> studentList = stuMap.getValue();
System.out.println("classId:"+classId+",studentList:"+studentList.toString());
}}
collect.for((k,v) -> {
String classId = k;
List<Student> studentList = v;
System.out.println("classId:"+classId+",studentList:"+studentList.toString());
})
Map<String, Long> shiftDateQtyMap = hmeLineShiftProgressVO4s.stream().collect(Collectors.toMap(HmeLineShiftProgressVO4::getShiftDate, HmeLineShiftProgressVO4::getQty));
排序
exceptionVoList.stream().sorted(Comparator.comparing(HmeExceptionHandlePlatFormVO::getOrderBy)).collect(Collectors.toList());
resultList.stream().sorted(Comparator.comparing(HmeCompletedAttachmentVO3::getSeq)
.thenComparing(HmeCompletedAttachmentVO3::getCreationDate).reversed()).collect(Collectors.toList());
Map<Date, List<HmePreprocessWorkcellVO>> collect =workcellVOS.stream().collect(Collectors.groupingBy(HmePreprocessWorkcellVO::getCreationDate));
collect.entrySet().stream().sorted(Map.Entry.comparingByKey());
筛选
List.stream().filter(item ->
respondEmployeeId.equals(item.getRespondEmployeeId())
).findAny().isPresent()
去重
list.stream().distinct();
计算
BigDecimal qtySum = dto1.getDetailDTOList().stream().map(t -> BigDecimal.valueOf(t.getPrimaryUomQty())).reduce(BigDecimal.ZERO, BigDecimal::add);
ist.stream().mapToDouble(User::getHeight).sum()
list.stream().mapToDouble(User::getHeight).max()
list.stream().mapToDouble(User::getHeight).min()
list.stream().mapToDouble(User::getHeight).average()
list.add("test1");
list.add("test2");
list.add("test3");
AtomicInteger index = new AtomicInteger(0);
list.stream()
filter(s -> {
index.getAndIncrement();
return s.equals("test2");
})
.findFirst();
System.out.println(index.get());