Here’s the hierarchical structure of the given interfaces in the Java Collections Framework (JCF):
┌──────────────────────┐
│ Iterable<E> │ (Superinterface of Collection)
└──────────▲───────────┘
│
┌─────────┴──────────┐
│ Collection<E> │ (Root interface for List & Set)
└─────────▲──────────┘
│
┌──────────────┴──────────────┐
│ │
List<E> Set<E>
│ │
│ ├───────────┐
│ │ │
│ SortedSet<E> (Set with ordering)
│ │
│ ▼
│ NavigableSet<E> (Extends SortedSet)
▼
(Implementations: ArrayList, LinkedList, Vector, Stack)
──────────────────────────────────────────────────────────
Map<K, V> (Separate hierarchy)
│
├──────────────┐
│ │
SortedMap<K, V> (Map with ordering)
│
▼
NavigableMap<K, V> (Extends SortedMap)
Explanation of Hierarchy:
Iterable<E>
– The topmost interface, allowing iteration over elements.Collection<E>
– ExtendsIterable<E>
and serves as the root forList<E>
andSet<E>
.List<E>
– Ordered collection (e.g.,ArrayList
,LinkedList
).Set<E>
– Unordered collection, no duplicates (e.g.,HashSet
).SortedSet<E>
– ASet
with elements stored in sorted order (e.g.,TreeSet
).NavigableSet<E>
– ExtendsSortedSet
with navigation methods likehigher()
,lower()
.
Map<K, V>
– A separate hierarchy that stores key-value pairs.SortedMap<K, V>
– AMap
where keys are stored in sorted order (e.g.,TreeMap
).NavigableMap<K, V>
– ExtendsSortedMap
, providing extra methods for navigation (e.g.,TreeMap
).
Key Takeaways:
Collection<E>
is the root forList<E>
andSet<E>
, butMap<K, V>
is a separate hierarchy.SortedSet<E>
andSortedMap<K, V>
enforce natural ordering or a custom comparator.NavigableSet<E>
andNavigableMap<K, V>
provide enhanced navigation methods.