Java Utility Library

Java Arrays - toString() Method



The java.util.Arrays.toString() method returns a string representation of the contents of the specified array. If the array contains other arrays as elements, they are converted to strings by the Object.toString() method inherited from Object, which describes their identities rather than their contents.

Syntax

public static String toString(Object[] a)

Parameters

a Specify the array whose string representation to return.

Return Value

Returns string representation of the array.

Exception

NA.

Example:

In the example below, the java.util.Arrays.toString() method returns a string representation of the given array object.

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //creating an array object
    Object Arr[] = {10, 5, 25, -5, 48};

    //convert the array into a string
    String MyStr = Arrays.toString(Arr);

    //print the string
    System.out.println(MyStr);  
  }
}

The output of the above code will be:

[10, 5, 25, -5, 48]

❮ Java.util - Arrays