Convert Array to String using Arrays class - Java java.util

Java examples for java.util:Arrays

Description

Convert Array to String using Arrays class

Demo Code


import java.util.Arrays;

class CollectionMain {
  public static void main(String[] args) {
    int arr[] = { 2, 3, 4, 5, 3, 5, 6, 1 };
    Integer arr1[] = { 2, 3, 4, 5, 3, 5, 6, 1 };
    // Will Not print array value beacuse array does'nt override toSring
    // method//  w  w  w . j a va 2 s .c  o  m
    System.out.println(arr);
    System.out.println(arr.toString());
    // Print List of arrays as string
    System.out.println(Arrays.toString(arr));
    // Can convert only objects
    System.out.println(Arrays.deepToString(arr1));

  }
}

Related Tutorials