Java Array toString

Doing a toString on a array don’t really tell that much about the array. Here is one way to get the contents of the array as a string.

int[] myArray = new int[2];
myArray[0] = 1; myArray[1] = 2;
System.out.println("array contains " + java.util.Arrays.toString(myArray));
 
//will output array contains [1, 2]