Home Java SCJP SCWCD Servlet Submit News Contact Us Site Map


Over 500 magazines for free (including Oracle Magazine)!

Yes all of them are FREE. You can subscribe to ALL of them.
Click here to apply today!

Home > Java > Java Articles

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.

 

<< Accessing Array Elements

Multidimensional Array Example>>

 

Home Java SCJP SCWCD Servlet Site map