Multi-Dimensional Arrays

A multi-dimensional array is an extension of a regular array that allows storing data in multiple dimensions—such as rows and columns, or more.

What is a Multi-Dimensional Array?

It is essentially an array of arrays. For example, a two-dimensional array can be thought of as a table with rows and columns.

Key Characteristics:

Example of a Two-Dimensional Array in Python:

matrix = [
  [1, 2, 3],
  [4, 5, 6],
  [7, 8, 9]
]

# Access element in 2nd row, 3rd column (indexing starts at 0)
print(matrix[1][2])  # Output: 6

Example of a Two-Dimensional Array in Java:

// Declare and initialize 2D array
int[][] matrix = {
  {1, 2, 3},
  {4, 5, 6},
  {7, 8, 9}
};

// Access element at row 1, column 2
System.out.println(matrix[1][2]);  // Output: 6

Applications of Multi-Dimensional Arrays:

Multidimensional arrays are powerful tools for organizing complex data structures in efficient ways and form a critical foundation for many algorithms.