This question has already been answered:

There is a code. Eclipse does not produce errors. However, at compilation, abracadabra is displayed, but in the debugger (inside) everything is ok. What's wrong? Thank you in advance!

package arrays; //Returning an Array from a Method public class TestArrays4 { public static int[] reverse(int[] list) { int[] result = new int[list.length]; for (int i = 0, j = result.length - 1; i < list.length; i++, j--){ result[j] = list[i]; } return result; } public static void main(String[] args) { int[] a = {1, 2, 3}; int[] c = reverse(a); System.out.println("hi " + c); } } 

in console

 hi [I@1db9742 

Marked as a duplicate by the participants of zRrr , Yuriyi SPb java Nov 16 '16 at 0:49 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

    1 answer 1

    The problem is that you incorrectly output the contents of the array to the console.

    In line:

     System.out.println("hi " + c); 

    an implicit call occurs to the toString() method of the Object class, which looks like this:

     public String toString() { return getClass().getName() + "@" + Integer.toHexString(hashCode()); } 

    As you can see, it returns the class name and the hexadecimal representation of the object's hashcode. Actually, this is what you get.

    You can output the contents of an array, for example, like this:

     for (int i=0; i<c.length; i++) { System.out.println(c[i]); } 

    or so:

     for (int i : c) { System.out.println(i); } 

    or so (java 8):

     Arrays.stream(c).forEach(System.out::println); 

    or you can use the Arrays class's toString(...) method:

     System.out.println(Arrays.toString(c));