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.
I am not allowed to use any import statements/ anything advanced to solve this - trying to possibly use a helper function?
Thanks :)
解决方案
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
You can use a for-loop to print each array element individually.
eg.
for (int i = 0; i < myArray.length; i ++) {
System.out.println(myArray[i]);
}
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"