Ross, you can also use Arrays.copyof () or Arrays.copyOfRange ().
Integer[] integerArray = Arrays.copyOf(a, a.length, Integer[].class); Integer[] integerArray = Arrays.copyOfRange(a, 0, a.length, Integer[].class);
Here's the reason for ClassCastException a ClassCastException is that you cannot treat an Integer array as an Object array. Integer[] is a subtype of Object[] , but Object[] not Integer[] .
And the following also will not give ClassCastException .
Object[] a = new Integer[1]; Integer b=1; a[0]=b; Integer[] c = (Integer[]) a;
namalfernandolk Nov 21 '11 at 11:59 a.m. 2011-11-21 23:59
source share