VOOZH about

URL: https://www.geeksforgeeks.org/java/arrays-tostring-in-java-with-examples/

⇱ Arrays.toString() in Java with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Arrays.toString() in Java with Examples

Last Updated : 14 Apr, 2026

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.

  • Converts an array into a string containing all its elements.
  • For object arrays with nested arrays, it prints memory references instead of actual values.
  • For nested arrays, Arrays.deepToString() should be used to get full content representation.

Output
[1, 2, 3, 4]

Syntax

public static String toString(int[] array)
public static String toString(Object[] array)

Parameters: array: The array, whose string representation to return.

Return Type:

  • String representation of the array's elements.
  • If the array is null, it returns the string "null".

Examples of Arrays.toString() in Java

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.


Output
[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


Output
[Roll No: 1, Name: a, Address: UP, Roll No: 2, Name: b, Address: MP, Roll No: 3, Name: c, Address: Delhi]
Comment
Article Tags:
Article Tags: