To my understanding, a List
is an ordered collection of items. And a Set
is a collection of unique items.
Now my question is, why does LinkedHashSet
, which describes an ordered collection of unique items, implement the Set
interface (=> unique), but not the List
interface (=> ordered)?
One possible argument is that List
is intended for random access datastructures, but that would be invalidated by the fact that LinkedList
doesn't have "true" random access either. In fact, LinkedHashSet
is backed by an internal linked list. Also the documentation for List
says otherwise:
Note that these [positional index] operations may execute in time proportional to the index value for some implementations.