class SortTest{
int index;
int count;
public SortTest(int index,int count) {
this.index = index;
this.count = count;
}
}
Arrays.sort(st, new Comparator<SortTest>() {
/****
* o1 后一个数
* o2 前一个数
*
* 0 不排序
* -1 交换
* 1 不交换
*/
@Override
public int compare(SortTest o1, SortTest o2) {
if(o1.count != o2.count) {
return o2.count - o1.count; //2-1降序
}
return o1.index - o2.index; //1-2 升序
}
});
Comparator基础使用
最新推荐文章于 2024-03-19 17:16:10 发布