Edgar Trania wrote:but im trying to say that i got confused with array semantics but nevermind then
Yes, it is a bit tricky.
The problem is that it's basically impossible to return a properly-typed generic array (in your case, a String), without either:
I'm guessing the designers chose the latter as the best compromise, since there's nothing to stop you writing:
String sa = sl.toArray(new String[s1.size()]);
and it will probably run quicker too.
Paul Clapham wrote:So are you clear about what is happening there? Or do you still have a question?
I have a question Paul. :) I read the documentation of this method. It says that
If the list fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this list.
So, in this case, since the String array being passed is of a size less than the number of elements in the list, a new String array will be created at run-time having a size 4. Correct?