读书人

对两个对象开展排序

发布时间: 2012-09-17 12:06:51 作者: rapoo

对两个对象进行排序
//声明存放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;
}
}

读书人网 >行业软件

热点推荐