想象一下这些课程
class Subject {
private int id;
private Type type;
private String origin;
private String name;
Subject(int id, Type type, String origin, String name) {
this.id = id;
this.type = type;
this.origin = origin;
this.name = name;
}
// Getters and Setters
}
enum Type {
TYPE1,
TYPE2
}
我有这些学科课程的列表
List<Subject> subjects = Arrays.asList(
new Subject(1, Type.TYPE1, "South", "Oscar"),
new Subject(2, Type.TYPE2, "South", "Robert"),
new Subject(3, Type.TYPE2, "North", "Dan"),
new Subject(4, Type.TYPE2, "South", "Gary"));
我想得到作为使用Collectors.groupingBy()
地图首先分组Subject
对象Subject.origin
然后分组的结果Subject.type
结果得到这样的对象Map<String, Map<Type, List<Subject>>>