January 2014
Intermediate to advanced
736 pages
70h 43m
English
Like one-dimensional arrays, multidimensional arrays can be initialized with array initializers in declarations. A two-dimensional array b with two rows and two columns could be declared and initialized with nested array initializers as follows:
int[][] b = { { 1, 2 }, { 3, 4 } };
The initial values are grouped by row in braces. So 1 and 2 initialize b[0][0] and b[0][1], respectively, and 3 and 4 initialize b[1][0] and b[1][1], respectively. The compiler counts the number of nested array initializers (represented by sets of braces within the outer braces) to determine the number of rows in array b. The compiler counts the initializer values in the nested array initializer for a ...
Read now
Unlock full access