Java的打印内存阵列的地址,而不是数组的内容 [英] Java prints array memory address rather than array contents
问题描述
我已经创建了发现的最大的3组在我的数组的函数。当我来到这个打印,存储地址[I @ 43c46747被打印出来,而应该被包含在数组中的最大值。
I have created a function which finds the maximum of groups of 3 in my array. When I come to print this, the memory address [I@43c46747 gets printed instead of the maximums which should be contained within the array.
我不允许使用任何import语句/先进的东西来解决这个? - 尝试可能使用一个辅助函数
I am not allowed to use any import statements/ anything advanced to solve this - trying to possibly use a helper function?
感谢:)
推荐答案
在实际上,你看到的是不是一个内存地址,但数组的类名和哈希值(十六进制形式)。这是从继承了行为的toString()
的java.lang.Object
In fact, what you see is not a memory address, but array's class name and hash value (in hex form). This is a behavior inherited from toString()
method of java.lang.Object
您可以使用一个for循环单独打印每个数组元素。
You can use a for-loop to print each array element individually.
如:
for (int i = 0; i < myArray.length; i ++) {
System.out.println(myArray[i]);
}
注意的println
打印的toString
非原始类型的数组元素的方法的结果。确保他们的的toString
如果你想定制行为是否正确重写,而不是类名@散列值
Note that println
prints the result of toString
method of the array elements for non-primitive types. Make sure their toString
is properly overriden if you want custom behaviour rather than "classname@hashvalue"
这篇关于Java的打印内存阵列的地址,而不是数组的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!