方法一:
//先分组
Map<String, List<Student>> map = list.stream().collect(
Collectors.groupingBy(Student::getName));
//再排序
for (Map.Entry<String, List<Student>> nmap : map.entrySet()) {
nmap.getValue().sort(Comparator.comparing(Student::getScore));
}
方法二:
//分组排序
Map<String, List<Student>> map = list.stream().collect(
Collectors.groupingBy(Student::getName, HashMap::new,
Collectors.collectingAndThen(Collectors.toList(),
//正序
list -> list.stream().sorted(Comparator.comparing(Student::getScore))
//倒序
//list -> list.stream().sorted(Comparator.comparing(Student::getScore).reversed())
.collect(Collectors.toList())
)));