I need to pass a primitive int array (int[]) via intent extras, and use them in an extended BaseAdapter class, so I need to convert int[] to Integer[]
How can I do this?
I need to pass a primitive int array (int[]) via intent extras, and use them in an extended BaseAdapter class, so I need to convert int[] to Integer[]
How can I do this?
I am afraid theres no better solution than this
int[] a1 = ...
Integer[] a2 = new Integer[a1.length];
for(int i = 0; i < a1.length; i++)
a2[i] = a1[i];
See following code:
int[] old = ....
Integer[] arr = new Integer[old.length];
System.arraycopy(old, 0, arr, 0, old.length);
Or you can use Apache lang library, then you can use the ArrayUtils.toObject(int[]) method like this:
Integer[] newArray = ArrayUtils.toObject(oldArray);
From @Eddie's answer here, you might want to look at this if you have access to the Apache lang library:
Integer[] newArray = ArrayUtils.toObject(oldArray);