Java中的奇怪数组输出

Geo*_*iev 0 java arrays output

我想知道为什么以及如何解决此数组方法输出的内存表示形式temp

public class StringMethodsExersice{
    public static int[] shiftMax(int[] num){
        int temp[] = new int[num.length];
        int firstEl = num[0];
        int lastEl = num[num.length-1];


        for(int i=1;i<num.length-1;i++){
            if(num[i] > num[i+1]){
                temp[i] = num[i];
            }
            temp[i] = num[i];
        }
        temp[0] = firstEl;
        temp[num.length-1]= lastEl;
        return temp;
    }

    public static void main (String []args){
        int[] myArray = new int [5];
        myArray [0] = 2;
        myArray [1] = 5;
        myArray [2] = 6;
        myArray [3] = 14;
        myArray [4] = 25;
        System.out.println(shiftMax(myArray));
    }
}
Run Code Online (Sandbox Code Playgroud)

Mar*_*oun 5

您可以使用Arrays#toString

System.out.println(Arrays.toString(shiftMax(myArray)));
Run Code Online (Sandbox Code Playgroud)

(有关详细信息,请参见其实现


关于获得的输出的说明:

由于每个对象都有toString()方法,因此默认值是显示类名称表示形式,然后添加@符号,然后添加哈希码。

  • 别再偷我的答案了!:P +1 (3认同)
  • 速度与激情。 (3认同)