原创

Java-Stream之Sort排序comparing和thenComparing-多个字段自定义排序

List<EduTrainExamVo> eduTrainExamVos = JSON.parseArray("xxx",EduTrainExamVo.class);
//另外可参考:https://blog.csdn.net/Danny1992/article/details/103531723

//只按examId降序
eduTrainExamVos.sort(Comparator.comparing(EduTrainExamVo::getExamId,Comparator.reverseOrder()));
//先按trainLevel升序,再按examId降序

//eduTrainExamVos.sort(Comparator.comparing(EduTrainExamVo::getTrainLevel).thenComparing(EduTrainExamVo::getExamId, Comparator.reverseOrder()));

System.out.println(eduTrainExamVos);

正文到此结束
本文目录