In addition to storing the length of the array, an array of int
s needs space for N 4-byte elements, while an array of Integer
s needs space for N references, whose size is platform-dependent; commonly, that would be 4 bytes on 32-bit platforms or 8 bytes on 64-bit platforms.
As far as int[]
goes, there is no additional memory required to store data. Integer[]
, on the other hand, needs objects of type Integer
, which could be all distinct or shared (e.g. through interning of small numbers implemented by the Java platform itself). Therefore, Integer[]
requires up to N additional objects, each one containing a 4-byte int
.
Assuming that all Integer
s in an Integer[]
array are distinct objects, the array and its content will take two to three times the space of an int[]
array. On the other hand, if all objects are shared, and the memory costs of shared objects are accounted for, there may be no additional overhead at all (on 32-bit platforms) or the there would be a 2x overhead on 64-bit platforms.