Run time exception-- java.lang.ClassCastingException
...
Integer intArr[] = new Integer[arrList.size()];
ArrayList <Integer> arrList =new ArrayList();
intArr=(Integer[])arrList.toArray(); // returns Object class which is downcaste to Integer;
I understand down-casting is not safe but why is this happening?
I also tried to converting ArrayList
to String
to Integer
to int
, but I get the same error.