A multi-dimensional array in Java is an array of arrays. The most common form is a two-dimensional array, which is useful for representing tables, matrices, grids, or structured data.
0Java supports multi-dimensional arrays by nesting array brackets. Memory is allocated row-wise.
// Declaration of a 2D integer array
int[][] matrix;
// Creating and initializing a 2D array
int[][] numbers = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
// Printing elements using nested loops
for(int i = 0; i < numbers.length; i++){
for(int j = 0; j < numbers[i].length; j++){
System.out.print(numbers[i][j] + " ");
}
System.out.println();
}
1 2 3
4 5 6
7 8 9
The outer loop controls rows, while the inner loop accesses columns of each row.
Click a cell to see how to access it in Java:
array.length for rows and array[row].length for columns