Collection排序

来源:互联网 发布:网络舆情公司排名 编辑:程序博客网 时间:2024/05/16 06:01

使用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升序排列}});



0 0
原创粉丝点击