0

The point of Java's ArrayLists is that they adjust their length automatically whenever items are inserted or deleted. If I understand it correctly, ArrayLists are wrappers around primitive arrays.

I was taught that:

  • arrays are data structures that offer random access in O(1) but can do insertion and deletion only in O(n), while
  • lists offer insertion and deletion in O(1) but provide random access only in O(n),

meaning that a data structure can't be an array and a list at the same time.

Why then does Java call it “ArrayList” – isn't that an oxymoron? (Wouldn't “DynamicArray” be more appropriate?) Or do ArrayLists actually have a “lists trope”?

Pixelcode
  • 103
  • 2

1 Answers1

0

Peanuts are neither a pea, nor a nut. What's up with that?

My point is that naming isn't required to follow whatever rule you are imagining. An ArrayList is not an array, and not a list. It has some aspects in common with an array, and some aspects with a list, but it is not identical with either. That is fine. It is still a fine name.

D.W.
  • 167,959
  • 22
  • 232
  • 500