看看Collections,基础要打牢啊

解决方案 »

  1.   

    ArrayList不排序
    直接按放入顺序排列
    要想排序,如楼上所说,用Collections类
      

  2.   

    听楼上的2位的,JAVA 的java.util.Collections类提供很多静态的方法,sort();swap();等来对数组操作。
      

  3.   

    先用java.util.ArrayList.toArray() 方法变成普通数组,再用Arrays.sort()方法排序
    自己编的算法显然不如sort()的这种quickSort算法来的快。
      

  4.   

    为什么不能?
    Collections.sort(arraylist, Comparator);
    实现一个Comparator来确定排序的规则。
      

  5.   

    看看java.util.Collections的api,都是static的,ArrayList实现了List
    sort(List<T> list) 
              Sorts the specified list into ascending order, according to the natural ordering of its elements.sort(List<T> list, Comparator<? super T> c) 
              Sorts the specified list according to the order induced by the specified comparator.
      

  6.   

    对阿,数组排序用java.util.Arrays类,Collection容器排序使用java.util.Collectios类。Arrays和Collections类包含了一些静态方法用于填充,排序,查找等操作。
      

  7.   

    补充下楼上的一些观点:
    如果你是ArrayList[] arr = new ArrayList[10]数组的话 ,想用Arrays.sort(arr) 是错误的,
    原因在于ArrayList本身这个对象没有实现comparable这个接口.
    所以 你要根据你自己的业务实现来写个类 去实现 comparator这个接口 
    然后用Arrays.sort(arr,comparator);来对你的数组去排序  所以以后大家不管是要用Arrays.sort() 还是Collections.sort()
    一定要注意你的数组(集合)里面的对象类 要实现comparable这个接口 ,或者去自己实现个comparator类!