What does the method toString(int[] a) do?


The toString(int[]) method of the class java.util.Arrays return a string representation of the contents of the specified int array. The string representation consists of a list of the array's elements, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ", " (a comma followed by a space).

Example

import java.util.Arrays;
public class ArrayDemo {
   public static void main(String[] args) {
      int[] i1 = new int[] { 33, 12, 98 };
      System.out.println("The array is:");
      for (int number : i1) {
         System.out.println("Number = " + number);
      }
      System.out.println("The string representation of array is:");
      System.out.println(Arrays.toString(i1));
   }
}

Output

The array is:
Number = 33
Number = 12
Number = 98
The string representation of array is:
[33, 12, 98]

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 13-Mar-2020

35 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements