More on Arrays
Arrays of arbitrary objects can be constructed, e.g.:
Color manycolors[] = new Color[1024];
- In this case, an array of object references is created; before you use the array elements, you may need to use object constructors to allocate each element (see later).
In particular, multidimensional arrays are arrays of arrays. In general these arrays may be “ragged”:
int graph[][] = new int[2][];
graph[0] = new int[4]; // Row 0 has length 4
graph[1] = new int[7]; // Row 1 has length 7
. . .
graph[1][1] = 9;
- Alternative syntax for creating a rectangular array:
char icon[][] = new char[16][16]; // 16 by 16 array