Privacy Policy Terms Of Use. Copyright © 2006-2010 Java Tutorials and Examples.
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
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.
<< Accessing Array Elements Multidimensional Array Example >>

Post new comment