![]() |
VOOZH | about |
The Arrays.toString() method in Java, available in the java.util.Arrays class, is used to convert an array into a readable string format. It returns a string representation of all elements in the array.
[1, 2, 3, 4]
public static String toString(int[] array)
public static String toString(Object[] array)
Parameters: array: The array, whose string representation to return.
Return Type:
null, it returns the string "null".Example: Using Arrays.toString() with Primitive Arrays
When we need to print or log the contents of a primitive array, we use Arrays.toString() method that converts a primitive array into a string representation.
Note: char[] is a special case and can be printed directly using System.out.println() as a sequence of characters.
[true, true, false, true] [10, 20, 30] [g, e, e, k, s] [1.0, 2.0, 3.0, 4.0] [1.0, 2.0, 3.0, 4.0] [1, 2, 3, 4] [1, 2, 3, 4] [1, 2, 3, 4] [1, 2, 3, 4]
Example: Using Arrays.toString() with Object Arrays
[Roll No: 1, Name: a, Address: UP, Roll No: 2, Name: b, Address: MP, Roll No: 3, Name: c, Address: Delhi]