Information Technology Reference
In-Depth Information
Jagged Arrays
A jagged array is an array of arrays. Unlike rectangular arrays, the sub-arrays of a jagged array
can have different numbers of elements.
For example, the following code declares a two-dimensional jagged array. The array's lay-
out in memory is shown in Figure 14-10.
The length of the first dimension is 3.
The declaration can be read as “
jagArr
is an array of three arrays of
int
s.”
Notice that the figure shows
four
array objects—one for the top-level array, and three for
the sub-arrays.
int[][] jagArr = new int[3][]; // Declare and create top-level array.
... // Declare and create sub-arrays.
Figure 14-10.
A jagged array is an array of arrays.