How to Print Multidimensional Array in Java

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

[[[email protected]
[[[email protected], [[email protected], [[email protected], [[email protected], [[email protected]]
[[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]]
[[[[email protected]
[[[[email protected], [[[email protected]]
[[[10, 20], [10, 30]], [[30]]]

References

1. JavaDoc – Arrays Class

Hello everyone, I am a Founder of dineshkrish.com.