Arrays in Java and how they are stored in memory

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.

Leave a Comment

tech