ArrayList to an Array
I am trying to change an ArrayList to an Array. I have tried the following code:
ArrayList myList=new ArrayList();
// Added some things here.
String[ ] myArray = myList.toArray(new String[0]);
When I try this I get an error saying "Cannot find symobl: variable String.
What am I doing wrong.
[426 byte] By [
jdub53a] at [2007-11-27 9:48:39]

String[ ] myArray = myList.toArray(new String[]{});
new String[]{} creates a new empty String array.
String[0] refers to the first element of an array variable called String, which doesn't exist, and saying new in front of that just blows the compiler's mind.
> I was missing the <String> tags. The tags got it to
> work. Thank you for all your help.
BTW, here's two tutorials on generics:
http://java.sun.com/docs/books/tutorial/java/generics/index.html
http://java.sun.com/docs/books/tutorial/extra/generics/index.html
Of course, if you are not using Generics, you can still convert an ArrayList to an array.ArrayList list = new ArrayList();String [] arr = (String[])(list.toArray(new String [list.size()]));~Tim