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
source
share