list实现从大到小排序
public static void main(String[] args) {
List<Integer> list=new ArrayList<Integer>();
//产生10以内的随机数
int num = 10;
for(int i=1;i<=num;i++){
list.add(i);
}
for(Object o : list){
System.out.println(o);
}
System.out.println("++++++++++++++++++++++++++++++++++++");
Collections.sort(list, new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
if (o1> o2) {
return -1;
} else if (o1 < o2) {
return 1;
}
return 0;
}
});
for(Object o : list){
System.out.println(o);
}
}
本文来自博客园,作者:up~up,转载请注明原文链接:https://www.cnblogs.com/soft-engineer/p/14985907.html