2D Arrays

Lesson 8 of 20

From rows to grids: store values in table[row][column] cells and visit every one with a loop inside a loop.

The big picture

From row to grid

A 2D array is a table: cells live at table[row][column], and nested loops walk them row by row.

Grid of cells

A 2D array is rows and columns — you address a cell with grid[row][column].

Two sizes

int[][] grid = new int[2][3] makes 2 rows, each with 3 zero-filled cells.

Nested loops fill it

The outer loop walks rows, the inner loop walks the columns of each row.

Two lengths

grid.length counts rows; grid[0].length counts the cells in row 0.