ArrayList.toArray() behaviour in JDK 1.5
807607Nov 24 2006 — edited Nov 24 2006Hello,
Can someone tell me what is wrong with following code
public static void main(String[] args){
ArrayList<String> a = new ArrayList();
a.add("one");
a.add("twp");
String[] array = a.toArray();
// Even this one does not work and gives a class cast exception
String[] array = (String[]) a.toArray();
for (int i=0;i<array.length;i++)
System.out.println(array);
}