Some Background on Multidimensional Arrays
We have been working with what are called one-dimensional arrays.
Now we need to develop a bit of background on arrays with more indices
which are called multidimensional arrays.
When I first studied arrays using Fortran back in 1972 they weren't all that much different than what we are doing presently. Though I want to mention a couple things that were different from arrays in Java. One thing about arrays was they were subscripted in the form arrayName(i,j) or arrayName(i,j,k). Java will be somewhat different. Another example of something that was different back then was that every row of a two dimensional array needed to have the same number of elements. We will not need this restriction in Java. But rather than continue with these sorts of teaching through something that is no longer around I want to get to multidimensional arrays in Java.
In Java, multidimensional arrays are represented using square braces that are distinct for each dimension. So the elements of a multidimensional array are specified by the sequence displayed in the following table.
|1||arrayName[ i ]|
|2||arrayName[ i ][ j ]|
|3||arrayName[ i ][ j ][ k ]|
|n||arrayName[ i ][ j ] . . . [ m ]|
|This sort of segmentation of the subscripts is
justified by a number of reasons. For example, each row in a two
dimensional array in Java does not need to have the same number of
Carrying on with part of one of our earlier examples gives the following string array.
|orb = "Mercury"|
|orb = "Venus"|
|orb = "Earth"||orb = "Moon"|
|orb = "Mars"||orb = "Phobos"||orb = "Deimos"|
|Notice that every row does not have the same length.
For your elucidation and reference you should attempt to get comfortable
with the following.
We will put these into a program in the next webpage where we will also address initializing multidimensional arrays.