java stream 多字段排序

我觉得最实用的当属这种原形:

var comparator= Comparator.comparing((SocietyMember x)->x.getSocietyId())
                .thenComparing(x-> studentMap.get(x.getStudentUuid()).getMatchedOrgUuid())
                .thenComparing(x->studentMap.get(x.getStudentUuid()).getMatchedGradeUuid())
                .thenComparing(x->studentMap.get(x.getStudentUuid()).getMatchedClassUuid());

members.sort(comparator);

懂的自然懂,代码没经过精简,是项目中实际代码

posted on 2022-07-14 18:08  空明流光  阅读(403)  评论(0编辑  收藏  举报

导航