本文主要是介绍Collection排序,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
使用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升序排列}});
这篇关于Collection排序的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!