I have an array list say

ArrayList<String> list = ArrayList<String>();

Now I want to get the String array from this list. Simple huh?

String[] arr = list.toArray();

Wrong!!!!

toArray method returns an array of Object, not the template type (in this case String). Instead you have to call

String[] arr = list.toArray( new String[list.size()] );

What were they thinking?

Advertisements