如何对ArrayList进行排序? [英] How to sort an ArrayList?
本文介绍了如何对ArrayList进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在java中有一个双打列表,我想按降序排序ArrayList。
I have a List of doubles in java and I want to sort ArrayList in descending order.
输入ArrayList如下:
Input ArrayList is as below:
List<Double> testList = new ArrayList();
testList.add(0.5);
testList.add(0.2);
testList.add(0.9);
testList.add(0.1);
testList.add(0.1);
testList.add(0.1);
testList.add(0.54);
testList.add(0.71);
testList.add(0.71);
testList.add(0.71);
testList.add(0.92);
testList.add(0.12);
testList.add(0.65);
testList.add(0.34);
testList.add(0.62);
输出应该是这样的
0.92
0.9
0.71
0.71
0.71
0.65
0.62
0.54
0.5
0.34
0.2
0.12
0.1
0.1
0.1
推荐答案
Collections.sort(testList);
Collections.reverse(testList);
这将做你想要的。请记住导入集合
尽管!
That will do what you want. Remember to import Collections
though!
以下是收藏
的文档。
这篇关于如何对ArrayList进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文