• 3 Posts
  • 1.04K Comments
Joined 2 years ago
cake
Cake day: August 21st, 2024

help-circle















  • if you want my opinion (<- see now you can’t tell me i’m wrong, it’s an opinion) then the difference is that an array is by definition a memory address that’s designated as the beginning of an array, and it’s got an offset because the first element is at that specific address and further items are offset from that address. so you add the offset to the address to get the nth item. a list, meanwhile, can be basically any implementation under the hood, but it’s commonly a linked list. the way you get the nth index there is you count up from the first position. since the implementation is opaque and may be spread out in memory you can’t arithmetic your way to an index, you need to follow the pointers.

    java’s arraylist is a list backed by an array. java’s vector is a list backed by a linked list.