Hi ,
Please correct me if i am wrong.
ArrayList arList = new ArrayList();
arList.add("1");
arList.add("2");
String[] str = (String[])arList.toArray();
I know that above code will not be compiled.I need more info. why the code is not being compiled?.
My understandings:
we are adding String's "1" "2" to List.since List.add(Object) those strings are upcasted to generalized Object(i.e. java.lang.Object).so List.toArray() returns Object[].But each element of Object[] is java.lang.Object can be down casted to String since originally we added String to List.
I don't understand why it is giving compile time error?. Please validate my understandings
Thanks,
Krish.