Mathews Mathai Mathews Mathai - 5 years ago 96
Java Question

How can a string array store arrays?

I know that the array declaration below is correct:

String[][] arrayNew={{"teresa","human","jennifer"},{"18","20"},{"nothing"}};

I understand that
are two different object types in java.So how come the
string array arrayNew
is successfully storing three different arrays in it.
array can not store
but how come a
string array
is able to store

Answer Source

You are just creating a 2D array (An array of String array).

On this particular case, you created a jagged array.

You could do the same for int array as well:

int[][] array = {{1,2,3}, {4,5}, {6}};

Multidimensional arrays are array of arrays:

String[] arrayA;       //Array of Strings
String[][] arrayB;     //Array of (Array of Strings)
String[][][] arrayC;   //Array of (Array of (Array of Strings))
String[][][][] arrayD; //Array of (Array of (Array of (Array of Strings)))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download