What does the method toString(obj[] a) do in java?

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


import java.util.Arrays;

public class ArrayDemo {
   public static void main(String[] args) {
      Object[] ob1 = new Object[] { 10, 20 };
      System.out.println("The array is:");

      for (Object number : ob1) {
         System.out.println("Number = " + number);
      System.out.println("The string representation of array is:");


The array is:
Number = 10
Number = 20
The string representation of array is:
[10, 20]
Sai Subramanyam
Sai Subramanyam

Passionate, Curious and Enthusiastic.