How to create a char array in Java?

To create a char array in Java, do this: char[] array = new char[] { 'a', 'b', 'c' }.

Pre-filled array

char[] array = new char[] { 'a', 'b', 'c' };

// [a, b, c]
System.out.println(java.util.Arrays.toString(array));

Empty array

char[] array = new char[3];

// [ ,  ,  ] <-- NULL characters
System.out.println(java.util.Arrays.toString(array));

Empty, then filled array

char[] array = new char[3];
array[0] = 'X';
array[1] = 'Y';
array[2] = 'Z';

// [X, Y, Z]
System.out.println(java.util.Arrays.toString(array));