Stream<Student> studentStream = Stream.of( new Student(1, 1, "A", 80), new Student(1, 2, "B", 90), new Student(1, 3, "C", 100), new Student(2, 1, "D", 90), new Student(2, 2, "E", 100), new Student(2, 3, "F", 80), new Student(3, 1, "G", 100), new Student(3, 2, "H", 80), new Student(3, 3, "I", 90) ); Map<Integer, Map<Integer, Map<Integer, List<Student>>>> groupGC = studentStream.collect( Collectors.groupingBy(s->s.gradeId, Collectors.groupingBy(s->s.classId, Collectors.groupingBy(s->s.score)) )); System.out.println(groupGC); //////////////////////////////////////////////////////////////////////////////////// class Student { int gradeId; int classId; String name; int score; Student(int gradeId, int classId, String name, int score) { this.gradeId = gradeId; this.classId = classId; this.name = name; this.score = score; } @Override public String toString() { return this.name; } }
Sign in to make a reply
_崔先生_