What do we mean by Multi-Dimensional Arrays in Java ?.
Multi-Dimensional Arrays in Java are termed as arrays of arrays. Normal arrays are objects in Java, while if we talk about Multi-Dimensional arrays, those are array objects whose elements themselves store array objects. Two Dimensional arrays are basic representation of tables having rows and columns. Thus, the information stored in two dimensional array is generally in rows and columns. Let us look into a simple program that demonstrate Multidimensional Arrays in Java :-
Output of the program :-
Multi-Dimensional Arrays in Java are termed as arrays of arrays. Normal arrays are objects in Java, while if we talk about Multi-Dimensional arrays, those are array objects whose elements themselves store array objects. Two Dimensional arrays are basic representation of tables having rows and columns. Thus, the information stored in two dimensional array is generally in rows and columns. Let us look into a simple program that demonstrate Multidimensional Arrays in Java :-
package com.hubberspot.multidimensional.array.example; public class TwoDimensionalArrayDemo { public static void main(String args[]) { int twoDArray[][]= new int[5][5]; int i, j, k = 0; for(i=0; i<5; i++) for(j=0; j<5; j++) { twoDArray[i][j] = k; k++; } for(i=0; i<5; i++) { for(j=0; j<5; j++) System.out.print(twoDArray[i][j] + " "); System.out.println(); } } }
Output of the program :-