我想ArrayList
使用布尔类型对我进行排序。基本上我想先显示条目true
。下面是我的代码:
ABC.java
public class Abc {
int id;
bool isClickable;
Abc(int i, boolean isCl){
this.id = i;
this.isClickable = iCl;
}
}
主.java
List<Abc> abc = new ArrayList<Abc>();
//add entries here
//now sort them
Collections.sort(abc, new Comparator<Abc>(){
@Override
public int compare(Abc abc1, Abc abc2){
boolean b1 = abc1.isClickable;
boolean b2 = abc2.isClickable;
if (b1 == !b2){
return 1;
}
if (!b1 == b2){
return -1;
}
return 0;
}
});
排序前的顺序:真真真假假假假真假假
排序后排序:false false true true true false false false false