匿名内部类排序comparator
时间: 2023-08-25 22:19:07 浏览: 101
匿名内部类
回答: 在填空处需要实例化一个匿名内部类来进行排序,代码如下:
Arrays.sort(a, new Comparator<Student>() {
public int compare(Student s1, Student s2) {
if (s1.age != s2.age) {
return s1.age - s2.age;
} else {
return s1.name.compareTo(s2.name);
}
}
});<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [【PTA】匿名内部类:实现Comparator比较器](https://blog.csdn.net/qq_63806300/article/details/127928435)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
- *3* [TreeSet【自然排序实现Comparable接口、定制排序匿名内部类 new Comparator】 的使用](https://blog.csdn.net/m0_64210833/article/details/123587487)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文