排序数组无效

时间:2015-10-08 10:44:58

标签: java arrays sorting

我正在尝试使用Arrays.sort(array)double[] myArray = {-5.502E-5, -6.854E-5, -1.920E-5, -2.121E-4, -2.587E-6}; double[] myArrayCopy = myArray; Arrays.sort(myArrayCopy); 数组进行排序:

myArrayCopy

$file没有任何变化。它保持未分类。可能是什么问题?

1 个答案:

答案 0 :(得分:1)

要检查阵列是否已排序,可以在阵列中插入新的数字2。要复制数组,可以使用Arrays.copyOf:

    double[] myArray = {-5.502E-5, 2, -6.854E-5, -1.920E-5, -2.121E-4, -2.587E-6};
        double[] myArrayCopy = Arrays.copyOf(myArray, myArray.length);;
        Arrays.sort(myArrayCopy);

        for (double n : myArrayCopy) {
            System.out.print(" " + n);
        }
        System.out.println("");
        for (double n : myArray) {
            System.out.print("" + n);
        }