Java Multidimensional Array
In java, multidimensional ( array of arrays) can be defined using
following syntax.
<type> arrayName[]…[];
or
<type>[]…[] arrayName[];
Where []…[] denotes number of dimension.
We can also combine array declaration and array construction in
one statement as follows.
<type>[]…[] arrayName = new <type>[]…[];
Example of declaring multidimensional array
int myIntArray[][] = new int[5][5];
String myStringArray[][] = new String[5][5];
Multidimensional can also be created and initialized in single expression
as follows.
int myIntArray[][] = {
{1,2,3},
{4,5,6}
}
Note: While constructing multidimensional array, length of deeply
nested array can be omitted which will not be constructed.
For example,
int myIntArray[][][] = new int[1][2][];
Deeply nested array can be constructed later on using loop.
|