🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
### 2.4.1 Comparator复合 排序器(Comparator)接口有以下2个常用方法: - **reversed**:逆序 - **thenComparing**:比较器链 ```java import java.util.Comparator; public class ComplexComparatorTest { public static void main(String[] args) { /* 按照height排序 */ Comparator<Model> c1 = Comparator.comparing(Model::getHeight); /* 先按照height降序排序,再按照name升序排序 */ Comparator<Model> c2 = Comparator .comparing(Model::getHeight) .reversed() .thenComparing(Model::getName); } static class Model { private Integer height; private String name; public Integer getHeight() { return height; } public void setHeight(Integer height) { this.height = height; } public String getName() { return name; } public void setName(String name) { this.name = name; } } } ```