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 :)

trincot
  • 317,000
  • 35
  • 244
  • 286
DJP
  • 13
  • 1
  • 4
  • 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. – markspace Oct 06 '18 at 23:17

1 Answers1

-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

Raj
  • 1