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

Java Programming Programming

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]
raja
Published on 24-Apr-2018 12:17:30
Advertisements