V
V
viktormarkov2016-10-27 13:36:17
Java
viktormarkov, 2016-10-27 13:36:17

Are array elements in Java stored on the stack or on the heap?

Hello, I have a mess in my head.
Arrays themselves in Java are objects, hence they live on the heap.
If the array contains objects, for example objArray [0] = new SomeObject();, then it is logical to assume that this element is also on the heap.
And if the array consists of primitives, intArray[0] = 1;are they stored as array instance variables on the heap, or as its local variables on the stack?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evhen, 2016-10-27
@viktormarkov

in the heap
In the Java programming language, arrays are objects...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question