1.、获取list中的某一项bean的集合
List<?> aList = list.stream().map(bean(实体类):: getId(字段)).collect(Collectors.toList());
2、按照Id分组
Map<Integer, List<Student>> collect3 = list.stream().collect(Collectors.groupingBy(Student::getId));
3、自定义函数分组
Map<Integer, List<Student>> collect4 = list.stream().collect(Collectors.groupingBy(stu -> stu.hashCode() % 5));
之后 通过遍历map的方法得到 分组条件的对应的list集合
for (collect3 .Entry<Integer, List<Student>> entry : collect3 .entrySet()) {
System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());
}
4,根据条件获取list中的bean
String a = "";
HairCheckItemResVo b = resultEnd.stream().filter(o -> a.equals(o.getGroup())).findFirst().orElse(null);
引用 : https://blog.csdn.net/qq_33142257/article/details/62891612