Comparator
2019-06-26 20:32 更新
Comparator 从小到大排序(即:o1,o2)Comparator:
class A implements Comparator<A>{
public int n;
@Override
public int compare(A o1, A o2) {
// TODO Auto-generated method stub
if (o1.n > o2.n) {
return 1;
} else if(o1.n == o2.n) {
return 0;
} else {
return -1;
}
}
}
以上内容是否对您有帮助:
更多建议: