I came across something new which i really found hard to understand.. Here is what i have done and it works perfectly fine..
Vector<String[]> v = new Vector<String[]>();
v.add(s);
String[][] s1 = new String[v.size][]
v.toArray(s1);
my question is how does it work even though method toArray() takes only 1-D array as argument..?
I’m not much old for java programming so seeking an explanation..
Thanks in advance..
There are only really 1-D arrays in Java – where it looks like you’ve got a multi-dimensional array, it’s actually just an array of arrays.
So if we ignore the fact that String[] itself is an array, and replace it with
StringArrayeverywhere, we get this code:Now that doesn’t look so odd, right?
s1is an array of string arrays, andvis a vector of string arrays.v.toArray()takes an array of string arrays as a parameter, so we can uses1as the argument.