//对agreeList进行排序 Collections.sort(agreeList,new Comparator(){ public int compare(Object obj1, Object obj2) { Transition transition1 = (Transition)obj1; Transition transition2 = (Transition)obj2; return transition1.getName().compareTo(transition2.getName()); } });
利用对象的name值进行排序,用 compareTo 进行比较 如果是int型,直接用 int a - int b
//对agreeList进行排序 Collections.sort(agreeList,new Comparator(){ public int compare(Object obj1, Object obj2) { Transition transition1 = (Transition)obj1; Transition transition2 = (Transition)obj2; return transition1.getName().compareTo(transition2.getName()); } });
//对集合进行排序 从大到小 Collections.sort((List<SaBillInfoDto>)billCollection, new Comparator<SaBillInfoDto>() {
@Override
public int compare(SaBillInfoDto o1, SaBillInfoDto o2) {
// TODO Auto-generated method stub
if ((o1.getBillAmount() - o2.getBillAmount()) > 0) {
return -1 ;
}else {
return 1 ;
}
}
});