ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
### 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; } } } ```