对两个对象进行排序
程序员文章站
2022-07-13 11:34:47
...
//声明存放A对象的集合
List<A> exceptionlevelVoList = new ArrayListList<A>();
//先排序(倒序)
Collections.sort(exceptionlevelVoList, new ACompator() );
class ACompator implements Comparator<A>{
public int compare(A a, A b) {
String levelA = a.getExceptionLevel();
String levelB = b.getExceptionLevel();
if(levelA.compareTo(levelB)>0) {
return -1;
}
if(levelA.compareTo(levelB)< 0){
return 1;
}
return 0;
}
}
List<A> exceptionlevelVoList = new ArrayListList<A>();
//先排序(倒序)
Collections.sort(exceptionlevelVoList, new ACompator() );
class ACompator implements Comparator<A>{
public int compare(A a, A b) {
String levelA = a.getExceptionLevel();
String levelB = b.getExceptionLevel();
if(levelA.compareTo(levelB)>0) {
return -1;
}
if(levelA.compareTo(levelB)< 0){
return 1;
}
return 0;
}
}
上一篇: 找出一个字符串中的数字