Multidimensional array Example Java Program


An array is a data structure consisting of a collection of elements (values or variables), each identified by at least one array index or key. An array is stored so that the position of each element can be computed from its index by a mathematical formula. The simplest type of data structure is a linear array, also called one-dimensional array. Multi dimensional arrays are nothing but arrays of arrays. You can create arrays of two or more dimensions. For a two-dimensional array, the element with indices i,j would have address B + c i + d j, where the coefficients c and d are the row and column address increments, respectively.


Data_type Variable_name[][] = new Data_type[Length][Length];

Multidimensional array Example Program

class TwoDimensionalArray{ 
	public static void main(String args[]) { 
		int twoDimenArray[][]= new int[3][5]; 
		int i, j, k = 0; 
		for(i=0; i<3; i++) 
		for(j=0; j<5; j++){ 
		twoDimenArray[i][j] = k; 
		for(i=0; i<3; i++){ 
			for(j=0; j<5; j++){
				System.out.print(twoDimenArray[i][j] + " ");

Sample Output

Output is:
0 1 2 3 4 
5 6 7 8 9 
10 11 12 13 14