x

Java – Multidimensional array

Prev     Next

Java Multidimensional Array are array of arrays. The inner member of the array would have equal number of elements.


Example For Java Multidimensional Array:

int[ ][ ] arr = new int[3] [5]; //all 3 rows would have 5 elements

int[ ][ ][ ] arr1 = new int[2][2][3]; //all 2 blocks of the 2 inner blocks would       have 3 elements

Jagged array is a special case of Multidimensional Array in which the member arrays of the array, can be of varying size.


Example:

int[ ][ ] arr = new int[2][];

arr[0] =new int[4];                    //Row1 contains 4 elements

arr[1] = new int[2];                   //Row2 contains 2 elements

int arr2[ ][ ] = {{2,3,4},{2,3}};

Note: Arrays can also be passed as an argument inside a method.

Prev     Next



Like it? Please Spread the word!