I don't know if it's a mental block for me or what but despite spending hours studying the questions asked already, I just can't pick up the final conclusion. I get lost and confused trying to comprehend so many different answers. :(
Please tell me the best way to do the following. I spent considerable time going through the existent questions but can't get the bottomline.
I'm trying to convert an arraylist into an array and while doing so, another question about object and array typecasting popped up.
ArrayList<Integer> al = new ArrayList<Integer>();
al.add(1);
al.add(2);
al.add(3);
Object[] oa = al.toArray();
int [] a = new int[al.size()];
a = (int[]) oa;
In the last line, it says I cannot cast from object[] to int[].
So, how do I typecast it then because the toArray method only returns an Object array.