Two Dimensional (2D) Arrays

Get a brief introduction to 2D arrays in Java.

We'll cover the following...

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 ...