Why EnumSet is not a SortedSet

Enum is comparable, but EnumSet is not a SortedSet.

While you can build

NavigableSet<EnumType> set = new TreeSet<EnumType>();
NavigableMap<EnumType, Object> map = new TreeMap<EnumType, Object>();

you cannot build

NavigableSet<EnumType> set = new EnumSet<EnumType>();
NavigableMap<EnumType, Object> map = new EnumMap<EnumType, Object>();

Since Enum is Comparable, this means it has a natural order that you can use in a general sorted collection, but not in a collection that is specific to Enums, which seems inconsistent.

Inserting, updating, and deleting in the tree is O (log n), while for the Enum collection its O (1)

EnumSet Collections Don't Know Enumeration Is Comparable?

Please provide a link to the duplicate question. If it is a duplicate

+4
source share

No one has answered this question yet.

Source: https://habr.com/ru/post/1620848/


All Articles