只是一個小的功能性的模塊,沒什麼難點。兩個知識點我其他博客有介紹
List的compare(T lhs, T rhs) :http://blog.csdn.net/u010137760/article/details/52238998
String的compareTo使用及釋義 :http://blog.csdn.net/u010137760/article/details/52231950
核心代碼
//對list進行排序,優先級 是否是默認助理、id
Collections.sort(addresses, new Comparator<AddressDomain>() {
@Override
public int compare(AddressDomain lhs, AddressDomain rhs) {
if(lhs.getDefaultFlag().compareToIgnoreCase(rhs.getDefaultFlag())<0){
return 1;
}else if(lhs.getDefaultFlag().compareToIgnoreCase(rhs.getDefaultFlag())==0){
return lhs.getId().compareToIgnoreCase(rhs.getId());
}else{
return -1;
}
}
});