created 12/03/99; revised 01/24/00

CHAPTER 49C --- Two-Dimensional Arrays

Often the data a program uses comes from a two dimensional situation. For example, maps are two dimensional (or more), the layout of a printed page is two dimensional, a computer-generated image (such as on your computer's screen) is two dimensional, and so on.

For these situations, a Java programmer can use a two-dimensional array. This can be thought of as a collection of "slots" laid out in a 2D grid. Each slot can hold a value (as with a 1D array). However, now two indexes are needed to specify a slot.

Chapter Topics:

  • Two-dimensional Arrays.
  • 2D Array Declaration.
  • Initializer Lists.
  • Differing Numbers of Elements in each Row.
  • 2D Arrays as Arrays of 1D Arrays.
  • Printing a 2D Array.
If you have used an application program known as a spreadsheet then you already have used a 2D grid for holding and manipulating data.

QUESTION 1:

(Thought question: ) Are 2D arrays implemented in the same main memory that 1D arrays and ordinary objects are implemented in?

Click Here after you have answered the question