In Java, array don't abrogate
toString()
, so in the event that you attempt to print one straightforwardly, you get the
className
+ '@' + the hex of the
hashCode
of the array, as characterized by
Object.toString()
:
int[] intArray = new int[] {1, 2, 3, 4, 5};
System.out.println(intArray); // prints something like '[I@3343c8b3'
Be that as it may, normally, we'd really need something more like
[1, 2, 3, 4, 5]
. What's the least complex method of doing that? Here are some example of inputs and outputs:
// Array of primitives:
int[] intArray = new int[] {1, 2, 3, 4, 5};
//output: [1, 2, 3, 4, 5]
// Array of object references:
String[] strArray = new String[] {"John", "Mary", "Bob"};
//output: [John, Mary, Bob]