1

I have a question about where in memory arrays are stored when arrays are initialized.

I understand that local variables and method parameters are stored in stack; objects are stored in heap.

What I am wondering is if an array is initialized, is there a difference where they are stored in below cases? Assume they are in the main method.

int[] a = {1,2,3,4,5};
int[] b = new int[a.length];

Thank you for your answer :)

1
  • 1
    I'm pretty sure the answer is no. Both of those arrays are stored in the heap. Arrays are objects so they always go on the heap. Commented Oct 6, 2018 at 23:17

1 Answer 1

-1

There should not be any difference in both since both are stored in heap. You could check link what does a java array look like in memory

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.