需求:需要针对集合进行排序,拥有字段a的对象排在前列,其他排在后面,字段a按大小排序,其余按字典序排序
Collections.sort(lm, new Comparator<Model>() {
@Override
public int compare(Model o1, Model o2) {A
if(o1.getA() != null && o2.getA() != null){
return Integer.valueOf(o1.getA()) - Integer.valueOf(o2.getA());
}else if(o1.getA() != null && o2.getA() == null){
return -1;
}else if(o1.getA() == null && o2.getA() != null){
return 1;
}else{
return o1.getName().compareTo(o2.getName());
}
}
});