java program to print 1D and 2D array directly without iteration


+ 1

import java.util.*;

public class ArrayPrinting {
public static void main(String[] args) {
int arr[]={1,2,3,4,5};
int arr1[][]={{1,2,3},{4,5,6}};
Integer ar[]={1,2,3,4,5};
Integer ar1[][]={{1,2,3},{4,5,6}};
//this will print the address of Array
System.out.println(arr);
//this will print exact array
System.out.println(Arrays.toString(arr));
//this will print address of sub Arrays
//so to avoid this we have to use deepToString()
//for multi dimensional Array
System.out.println(Arrays.toString(arr1));
//this will print exact Array
System.out.println(Arrays.deepToString(ar));
//this too print exact Array
System.out.println(Arrays.deepToString(ar1));
//this will print multi dimensional array exact.
System.out.println(Arrays.deepToString(arr1));
}
}