对两个对象进行排序

//声明存放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;
}
}

猜你喜欢

转载自huangshanghua.iteye.com/blog/1566082