Print Multidimensional Array in Java

In this example, We will show you simple program about, How to print multidimensional array in Java programming language. The example has been tested and shared in the same post.

Example Program

package com.dineshkrish;
import java.util.Arrays;
/**
* 
* @author Dinesh Krishnan
*
*/
public class PrintArray {
public static void main(String[] args) {
// 2d integer array
int[][] array = {{10, 20}, {30, 40}, {50, 60}, {70, 80}, {90, 100}};
System.out.println(array);
System.out.println(Arrays.toString(array));
System.out.println(Arrays.deepToString(array)); // printing
// 2d string array 
String[][] strArray = {{"One", "Two"}, {"Three", "Four"}, {"Five", "Six"}, {"Seven", "Eight"}, {"Nine", "Ten"}};
System.out.println(strArray);
System.out.println(Arrays.toString(strArray));
System.out.println(Arrays.deepToString(strArray)); // printing
// 3d integer array
int[][][] array2 = {{{10, 20}, {10, 30}}, {{30}}};
System.out.println(array2);
System.out.println(Arrays.toString(array2));
System.out.println(Arrays.deepToString(array2)); // printing
}
}

Output

[[I@3ee284
[[I@8965fb, [I@867e89, [I@1dd7056, [I@fa3ac1, [I@276af2]
[[10, 20], [30, 40], [50, 60], [70, 80], [90, 100]]
[[Ljava.lang.String;@e86da0
[[Ljava.lang.String;@1754ad2, [Ljava.lang.String;@1833955, [Ljava.lang.String;@291aff, [Ljava.lang.String;@ab95e6, [Ljava.lang.String;@fe64b9]
[[One, Two], [Three, Four], [Five, Six], [Seven, Eight], [Nine, Ten]]
[[[I@a97b0b
[[[I@cd2c3c, [[I@13582d]
[[[10, 20], [10, 30]], [[30]]]

References

1. JavaDoc – Arrays Class

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *