0
$\begingroup$

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”?

$\endgroup$
3
  • 1
    $\begingroup$ Your definition of List is specifically for a linked list. Anyway you can ask on langdev stack exchange for the reasons why langiages are designed the way they are. $\endgroup$ Commented Sep 30, 2024 at 1:33
  • $\begingroup$ I didn't know that “list” isn't a synonym for “linked list”, thanks! $\endgroup$ Commented Sep 30, 2024 at 15:07
  • 1
    $\begingroup$ Yes, "list" is an abstract data type that doesn't refer to one implementation specifically unless in certain contexts. Python lists are dynamic arrays, while Lisp specifically uses linked lists. I agree it should've been called DynamicArray, but naming is inconsistent across languages (similar spirit question langdev.stackexchange.com/questions/3955/…) $\endgroup$ Commented Sep 30, 2024 at 15:52

1 Answer 1

0
$\begingroup$

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.

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.