//按学生姓名分组
Map<String, List<Student>> map = students.stream().collect(Collectors.groupingBy(Student::getName));
//按学生姓名分组,List存放学号
Map<String, List<Long>> map = students.stream().collect(Collectors.groupingBy(Student::getName, Collectors.mapping(Student::getId, Collectors.toList())));
//按学生姓名分组,Set存放学号
Map<String, Set<Long>> map = students.stream().collect(Collectors.groupingBy(Student::getName, Collectors.mapping(Student::getId, Collectors.toSet())));
lamdba表达式对list分组
最新推荐文章于 2024-02-29 14:07:17 发布