Java8 中使用 Stream 对 List 根据字段分组
2年前
//根据scoreYear字段进行分组
Map<String, List<Score>> map = scoreList.stream().collect(Collectors.groupingBy(score -> score.getScoreYear()));
//根据scoreYear和studentId字段进行分组
Map<String, List<Score>> map = scoreList.stream().collect(Collectors.groupingBy(score -> score.getScoreYear()+'-'+score.getStudentId()));