I\'m trying to understand the array setup in java. Why must you initialize space for each each object in the array, after you have created the array. How is it stored in mem
Arrays in Java store one of two things: either primitive values (int
, char
, ...) or references (a.k.a pointers).
So, new Integer[10]
creates space for 10 Integer
references only. It does not create 10 Integer
objects (or even free space for 10 Integer
objects).
Incidentally that's exactly the same way that fields, variables and method/constructor parameters work: they too only store primitive values or references.