使用Collection的sort方法可以对List对象进行排序,其中Record为自己定义的类,包含value,index,count三个成员变量
ArrayList<Recorder> forSort = new ArrayList();
forSort.add(new Recorder(str, index, count));//插入数据
Collections.sort(forSort, new Comparator<Recorder>() {
public int compare(Recorder o1, Recorder o2) {
if(o1.getCount()!=o2.getCount())
return o2.getCount()-o1.getCount(); //按照count降序排列
else
return o1.getIndex() - o2.getIndex(); //按照index升序排列
}
});