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

Java 8Object Oriented ProgrammingProgramming

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.

Example

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:");
      System.out.println(Arrays.toString(ob1));
   }
}

Output

The array is:
Number = 10
Number = 20
The string representation of array is:
[10, 20]
raja
Published on 16-Jan-2018 11:21:52
Advertisements