CKTIS / Java
Arrays.toString — a text representation of an array
Arrays.toString returns a readable array representation as a String, with square brackets and separators between elements.
Version: Java SE 21; repository runtime, production runtime not attested
Syntax
Arrays.toString(array)
public static String toString(int[] a)Arrays.toString in java.util.Arrays is static. The toString(int[] a) overload returns a String such as [3, -1, 0], separating elements with a comma and space. Overloads also exist for other primitive types and Object[].
An empty array produces "[]"; a null reference produces the text "null". The example uses an int[] variable for null too.
Nested arrays are not expanded: the Object[] overload shows their identities instead of contents. Use Arrays.deepToString for nested contents. Do not confuse Arrays.toString(array) with array.toString().
Examples
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
int[] numbers = {3, -1, 0};
int[] missing = null;
System.out.println(Arrays.toString(numbers));
System.out.println(Arrays.toString(new int[0]));
System.out.println(Arrays.toString(missing));
}
}Result
[3, -1, 0] [] null
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.