How to print an array in Java?

To print an array in Java, use Arrays.toString.

Here's how you can print arrays of various types:

Print String array

String[] array = new String[] { "Hello", "World" };

// [Hello, World]
System.out.println(java.util.Arrays.toString(array));

Print int array

int[] array = new int[] { 55, 1, 79 };

// [55, 1, 79]
System.out.println(java.util.Arrays.toString(array));

Print long array

long[] array = new long[] { 55L, 1L, 79L };

// [55, 1, 79]
System.out.println(java.util.Arrays.toString(array));

Print double array

double[] array = new double[] { 1.5, 3.3 };

// [1.5, 3.3]
System.out.println(java.util.Arrays.toString(array));

Print float array

float[] array = new float[] { 1.5f, 3.3f };

// [1.5, 3.3]
System.out.println(java.util.Arrays.toString(array));