0

Where are the following const size arrays allocated in Java (heap/stack)?

float[] arr = new float[3];
float[] arr = {0,0,0};

Note, that the new keyword is not used on the second line.

tisch
  • 1,098
  • 3
  • 13
  • 30
  • @chrylis: I disagree about this being a duplicate question. The usage of the initializer list is not discussed in the linked Question. – tisch Mar 02 '15 at 16:35
  • 2
    Because it doesn't make any difference to where the object is stored. The fact that it _is_ an object means it will be stored on the heap. – Sotirios Delimanolis Mar 02 '15 at 16:43
  • The array goes on the heap, the pointer to the array is stored in the stack frame. This is true in both cases. – bhspencer Mar 29 '16 at 17:03

0 Answers0