Integer extends Number so in that sense Number becomes the superclass of int. I want to store an int array into a Number array..
I have the following code.However, it seems it is not allowed in java.
int[] b = {1,2};
Number[] a = b;
Why java does not allow me to store an int array in number array and how do I store this out ?
You can’t do that directly, because an “array-of-primitives” is not an “array-of-objects”. Autoboxing does not occur with arrays.
But you can use
ArrayUtils.toObject(b)(from commons-lang). This will create a new array of the wrapper type (Integer) and fill it with the values from the primitive array: