Arrays in Java and how they are stored in memory

后端 未结 3 1224
情话喂你
情话喂你 2020-11-29 08:56

I\'m trying to understand the array setup in java. Why must you initialize space for each each object in the array, after you have created the array. How is it stored in mem

3条回答
  •  粉色の甜心
    2020-11-29 09:29

    Arrays are continuous space of memory, so they look like more your first sketch:

    [object-reference][object-reference]

    array[0] = new class() will store in array[0] a reference to the new created object.

    class[] array = new class[10] will create an array of ten empty slots (or ten null references).

提交回复
热议问题