No announcement
 

Multidimensional Arrays

A multidimensional array has more than one array dimension, used for complex arrangement.

Example:

MultiDimensionalArrayDemo.java

package com.codingnous.tutorial;

public class MultiDimensionalArrayDemo {

	public static void main(String[] args) {

		// Declaring 2D array of size 5x4.
		int[][] twoDimensionalArray = new int[5][4];

		// Insert some data in 2D array.
		twoDimensionalArray[1][2] = 2;
		twoDimensionalArray[2][2] = 6;
		twoDimensionalArray[3][3] = 8;

		// Lets print the array.
		for (int i = 0; i < 5; i++) {
			for (int j = 0; j < 4; j++) {
				System.out.print(twoDimensionalArray[i][j] + " ");
			}
			System.out.println();
		}

	}
}

Output
0 0 0 0 0 0 2 0 0 0 6 0 0 0 0 8 0 0 0 0