Search⌘ K
AI Features

Multi-dimensional Arrays

Explore the concept of multi-dimensional arrays in Java, including how to structure arrays of arrays and access individual elements with multiple indices. Understand practical examples like matrices and implement programs to calculate sums of rows and columns. This lesson helps you develop skills to work with complex array structures and apply them in real-world programming tasks.

What is a multi-dimensional array?

In Java, a multi-dimensional array is an array that contains other arrays as its values or members. The container array is termed an outer array, and the member array is termed an inner array. An array is said to be a multi-dimensional array if it has another array as its members.

Can you think of some instances where we might have been using a structure that is the same as a multi-dimensional array? One such example is a crossword puzzle!

Individual values in multi-dimensional arrays

The individual values in a multi-dimensional array are accessed through the multiple index numbers used. The following is an example of the two-dimensional array:

array1[row number][column number];

Let’s take the example of the following array:

int[][] array1 = {{10, 20, 30},
        
...