Search⌘ K

Two Dimensional (2D) Arrays

Explore how two dimensional arrays work in Java including their row and column structure, creation, and value assignment. Understand these concepts to solve array problems effectively and prepare for the AP Computer Science A exam.

Introduction

The concept of two-dimensional arrays is built on the arrays (one-dimensional array). Remember: when we talked about arrays in real life, we referred to them as lockers. Well, the same can be done for 2D-arrays. Look at the image below.

Picture a 2D array as the combination of both rows and columns of small lockers. A row has horizontal elements. A column has vertical elements. In the picture above, there are two rows and four columns of lockers. In this case, to locate a locker, you address it as a locker in 1st row, 2nd column. You have to provide both the row and column number.

2D arrays in Java

Java stores 2D arrays as arrays of arrays. Each ...