Here’s the hierarchical structure of the given Java Collections Framework (JCF) interfaces:
┌───────────────────┐
│ Iterable<E> │ (Superinterface for collection iteration)
└────────▲──────────┘
│
┌────────┴────────┐
│ Collection<E> │ (Root interface for List & Set)
└────────▲────────┘
│
┌───────────────┴───────────────┐
│ │
List<E> Set<E>
│ │
│ ├───────────┐
│ │ │
│ SortedSet<E> (Sorted set)
│ │
│ ▼
│ NavigableSet<E> (Extended SortedSet)
│
▼
(Implementations: ArrayList, LinkedList, Vector, Stack)
──────────────────────────────────────────────────────────────────
Map<K, V> (Separate hierarchy)
│
├──────────────┐
│ │
SortedMap<K, V> (Sorted key-value pairs)
│
▼
NavigableMap<K, V> (Extended SortedMap)
──────────────────────────────────────────────────────────────────
Iterator<E> (Independent interface for iteration)
Explanation of the Hierarchy:
1. Iterable<E> (Superinterface for iteration)
- The topmost interface that allows any class to be iterated using a loop (
for-eachloop). - Implemented by
Collection<E>, which means all lists and sets are iterable.
2. Collection<E> (Base Interface for List & Set)
- Defines general methods for adding, removing, and checking elements.
- Implemented by
List<E>andSet<E>.
3. List<E> (Ordered Collection)
- Maintains insertion order and allows duplicate elements.
- Common Implementations:
ArrayList,LinkedList,Vector,Stack.
4. Set<E> (Unique Collection)
- No duplicate elements allowed.
HashSet,LinkedHashSet,TreeSetare common implementations.
5. SortedSet<E> (Sorted Set)
- Extends
Set<E>, ensures sorted elements. - Implementation:
TreeSet.
6. NavigableSet<E> (Enhanced SortedSet)
- Extends
SortedSet, adds methods like floor(), ceiling(), higher(), lower() for navigation. - Implementation:
TreeSet.
7. Map<K, V> (Separate Key-Value Collection)
- Stores elements as key-value pairs.
- Implementations:
HashMap,LinkedHashMap,Hashtable.
8. SortedMap<K, V> (Sorted Map)
- Extends
Map<K, V>, stores keys in sorted order. - Implementation:
TreeMap.
9. NavigableMap<K, V> (Enhanced SortedMap)
- Extends
SortedMap<K, V>, adds navigation methods (floorKey(),ceilingKey(), etc.). - Implementation:
TreeMap.
10. Iterator<E> (Independent Interface)
- Provides methods to iterate over collections (
hasNext(),next(),remove()). - Used by all collections that implement
Iterable<E>.
Key Takeaways
Iterable<E>→ Root interface for all collections that can be iterated (for-each loop).Collection<E>→ Parent ofListandSet, butMap<K, V>is separate.SortedSet<E>&SortedMap<K, V>→ Guarantee sorting.NavigableSet<E>&NavigableMap<K, V>→ Add navigation methods.Iterator<E>is an independent interface for iterating over collections.