首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 企业软件 > 行业软件 >

对两个对象开展排序

2012-09-17 
对两个对象进行排序//声明存放A对象的集合ListA exceptionlevelVoList new ArrayListListA()//先排

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

热点排行