List<Test01DTO> tt = new ArrayList<>();
Test01DTO t1 = new Test01DTO();
Test01DTO t2 = new Test01DTO();
Test01DTO t3 = new Test01DTO();
Test01DTO t4 = new Test01DTO();
Test01DTO t5 = new Test01DTO();
Test01DTO t6 = new Test01DTO();
t1.setName("张三丰");
t2.setName("李四");
t3.setName("王二");
t4.setName("令狐冲");
t5.setName("周芷若");
t6.setName("赵敏");
t1.setAge(100);
t2.setAge(23);
t3.setAge(40);
t4.setAge(40);
t5.setAge(33);
t6.setAge(34);
t1.setSex("男");
t2.setSex("男");
t3.setSex("男");
t4.setSex("男");
t5.setSex("女");
t6.setSex("女");
// 根据年龄倒叙,不写reversed(),默认升序
List<Test01DTO> collect = tt.stream().sorted(Comparator.comparing(Test01DTO::getAge).reversed()).collect(Collectors.toList());
// 先根据年龄升序,在根据性别倒叙
List<Test01DTO> collect1 = tt.stream().sorted(Comparator.comparing(Test01DTO::getAge).thenComparing(Test01DTO::getSex,Comparator.reverseOrder())).collect(Collectors.toList());
就是这样简便🤭