Arrays.sort 用的是哪些排序方法

解决方案 »

  1.   

    java中Arrays.sort使用了两种排序方法,快速排序和优化的合并排序。
    即基本类型数据(如int,short,long等)排序,合并排序用于对对象类型进行排序。
      

  2.   

    我看了看源码 
    对对象数组排序方法的名字是mergeSort
      

  3.   

    public static void sort(float[] a, int fromIndex, int toIndex) {
            rangeCheck(a.length, fromIndex, toIndex);
    sort2(a, fromIndex, toIndex);
        }    private static void sort2(double a[], int fromIndex, int toIndex) {
            final long NEG_ZERO_BITS = Double.doubleToLongBits(-0.0d);
            /*
             * The sort is done in three phases to avoid the expense of using
             * NaN and -0.0 aware comparisons during the main sort.
             */        /*
             * Preprocessing phase:  Move any NaN's to end of array, count the
             * number of -0.0's, and turn them into 0.0's. 
             */
            int numNegZeros = 0;
            int i = fromIndex, n = toIndex;
            while(i < n) {
                if (a[i] != a[i]) {
    double swap = a[i];
                    a[i] = a[--n];
                    a[n] = swap;
                } else {
                    if (a[i]==0 && Double.doubleToLongBits(a[i])==NEG_ZERO_BITS) {
                        a[i] = 0.0d;
                        numNegZeros++;
                    }
                    i++;
                }
            }
    快速排序吧!
      

  4.   

    快速排序,方法注释里面有,可以看API文档