Multidimensional Arrays

The arrays you have been introduced to thus far in the hour all have one dimension, so you can retrieve an element using a number ranging from 0 to the largest element number in the array. Some types of information require more dimensions to store adequately as arrays. An example would be the (x,y) coordinate system. If you needed to store a list of x and y coordinates that have a point marked on them, you could use a two-dimensional array. One dimension of the array could store the x coordinate, and the other dimension could store the y coordinate.

To create an array that has two dimensions, you must use an additional set of square brackets when creating and using the array. Consider the following:

 boolean[][] selectedPoint ...

Get SAMS Teach Yourself Programming with Java™ in 24 Hours, FOURTH EDITION now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.