Does an array object explicitly contain the indexes?

后端 未结 9 2061
时光取名叫无心
时光取名叫无心 2021-02-01 16:18

Since day one of learning Java I\'ve been told by various websites and many teachers that arrays are consecutive memory locations which can store the specified number of data al

9条回答
  •  盖世英雄少女心
    2021-02-01 17:10

    An array is a contigious memory allocation, which means if you know the address of the first element you can go to the next index by stepping to next memory address.

    The reference array is not the array address, but the way to reach the address (done internally) like normal objects. So you can say you have the position from where the array starts, and you can move a memory address by changing the indexes. So this is why indexes are not specified in the memory; the compiler just knows where to go.

提交回复
热议问题