Java – Multidimensional array

Prev     Next

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

Example:

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

Share this website !!!
Facebook Twitter Linkedin