原文:http://www.cnblogs.com/minshia/p/6283858.html
对数组的排序:
| 1 2 3 4 5 6 7 8 | //对数组排序publicvoidarraySort(){    int[] arr = {1,4,6,333,8,2};    Arrays.sort(arr);//使用java.util.Arrays对象的sort方法    for(inti=0;i<arr.length;i++){        System.out.println(arr[i]);    }} | 
对集合的排序:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | //对list升序排序    publicvoidlistSort1(){        List<Integer> list = newArrayList<Integer>();        list.add(1);        list.add(55);        list.add(9);        list.add(0);        list.add(2);        Collections.sort(list);//使用Collections的sort方法        for(inta :list){            System.out.println(a);        }    }    //对list降序排序    publicvoidlistSort2(){        List<Integer> list = newArrayList<Integer>();        list.add(1);        list.add(55);        list.add(9);        list.add(0);        list.add(2);        Collections.sort(list, newComparator<Integer>() {            publicintcompare(Integer o1, Integer o2) {                returno2 - o1;            }        });//使用Collections的sort方法,并且重写compare方法        for(inta :list){            System.out.println(a);        }    }<br>注意:Collections的sort方法默认是升序排列,如果需要降序排列时就需要重写conpare方法 | 
原文:http://www.cnblogs.com/lwx521/p/7627045.html