Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

Describe the main interfaces of the Collections Framework and where Map fits. Why does Map not extend Collection?

The Collections Framework has two separate trees. Iterable sits at the root of Collection, which splits into List, Set and Queue, with Deque under Queue and the sorted and navigable sets under Set; Map is its own tree, with SortedMap and NavigableMap below it, and Java 21 added SequencedCollection, SequencedSet and SequencedMap to both. Map does not extend Collection because it holds key-value pairs, and methods such as add(E) or contains(Object) have no single sensible meaning for a mapping, so Map offers collection views instead: keySet, values and entrySet.

Why this question is asked

We pick a collection type many times a day, and the interface we choose decides which operations callers can use and which implementations we can swap in later. Interviewers start with the hierarchy because it shows whether we know the contracts behind ArrayList and HashMap, not only the class names, and because the question of why Map stands apart tests whether we think about what an interface promises. In this answer, we will walk down the Collection tree, look at the Map tree, see why the two are separate, and see where the sequenced interfaces of Java 21 fit in.

1A Quick Recap: Interfaces and Implementations

The framework separates what a collection promises from how it stores data. The promises are interfaces, such as List or Set. The storage is in implementation classes, such as ArrayList, HashSet or TreeMap. Good code declares variables and parameters with the interface type, List<String> names = new ArrayList<>(), so that the implementation can change without touching the callers.

At the very top sits Iterable, which is not strictly a collection at all. It promises only one thing, an iterator(), and anything that implements it can be used in a for-each loop. Collection extends Iterable and adds the operations every group of elements shares: size, isEmpty, contains, add, remove, and bulk versions of these, plus stream().

2Walking Down the Collection Tree

List is an ordered collection that allows duplicates and gives access by index: get(2), set(0, x), add(1, y). ArrayList and LinkedList are its main implementations. Set is a collection without duplicates, decided by equals. HashSet makes no promise about order; LinkedHashSet keeps insertion order.

SortedSet extends Set and keeps its elements sorted, either by their natural order or by a Comparator, adding first(), last() and range views such as headSet. NavigableSet extends SortedSet with closest-match searches: floor, ceiling, lower, higher. TreeSet implements NavigableSet.

Queue is a collection designed for holding elements before processing them, usually in first-in, first-out order. It offers two families of methods: offer, poll and peek return a special value on failure, while add, remove and element throw. Deque, a double-ended queue, extends Queue so we can add and remove at both ends, which makes it usable as a stack too. ArrayDeque is the usual implementation, and PriorityQueue is a Queue ordered by priority rather than arrival.

The two trees side by side
InterfaceExtendsTypical implementation
CollectionIterable-
ListSequencedCollection (Java 21), CollectionArrayList, LinkedList
SetCollectionHashSet
SequencedSet (Java 21)SequencedCollection, SetLinkedHashSet
SortedSet / NavigableSetSequencedSet (21) / SortedSetTreeSet
QueueCollectionPriorityQueue
DequeQueue, SequencedCollection (21)ArrayDeque, LinkedList
MapnothingHashMap
SequencedMap (Java 21)MapLinkedHashMap
SortedMap / NavigableMapSequencedMap (21) / SortedMapTreeMap
Map has its own tree; nothing in it extends Collection or Iterable.

3The Map Tree

A Map stores pairs: each key maps to at most one value. Its core operations are put(key, value), get(key), containsKey, containsValue and remove(key). HashMap is the general-purpose implementation, LinkedHashMap keeps insertion order or access order, and TreeMap keeps keys sorted.

SortedMap and NavigableMap mirror their Set counterparts: SortedMap keeps keys in order and gives firstKey(), lastKey() and range views, and NavigableMap adds floorKey, ceilingEntry and similar searches. This is no accident. A TreeSet is actually built on a TreeMap, and a HashSet on a HashMap, with the set's elements stored as the map's keys.

4Why Map Does Not Extend Collection

Try to imagine Map as a Collection and the methods stop making sense. What would add(E element) add? A key with no value? A pair? What would contains(Object o) check: the keys, the values or the pairs? Each answer is plausible, and whichever one we choose, some callers would expect another. A Collection is a group of elements; a Map is a function from keys to values, and its contract is about lookup, not membership.

The designers chose the honest option: Map is its own interface, and when we do want to treat its contents as a collection, it gives us three views. These views are live, not copies: removing a key from keySet() removes the entry from the map.

Java
Map<String, Integer> stock = new HashMap<>(Map.of("apple", 3, "pear", 0));
Set<String> keys = stock.keySet(); // [apple, pear] (order not guaranteed)
Collection<Integer> counts = stock.values(); // [3, 0]
Set<Map.Entry<String, Integer>> entries = stock.entrySet();
counts.removeIf(n -> n == 0); // removes the pear entry from the map
System.out.println(stock); // {apple=3}
keys.add("plum"); // UnsupportedOperationException

Notice that the views support removal but not addition. Removing an element has one clear meaning, delete that entry, while adding a key to keySet() would leave the map without a value for it. values() is a Collection rather than a Set because two keys can map to equal values.

5Where the Sequenced Interfaces Fit

Before Java 21 there was no common type for collections with a defined encounter order. A List had get(0), a Deque had getFirst(), a LinkedHashSet had nothing at all. JEP 431 added SequencedCollection, which declares getFirst, getLast, addFirst, addLast, removeFirst, removeLast and reversed(). List and Deque now extend it. SequencedSet extends both SequencedCollection and Set, and LinkedHashSet and SortedSet sit below it. On the Map side, SequencedMap adds firstEntry, lastEntry, putFirst, pollFirstEntry and reversed(), and is implemented by LinkedHashMap and extended by SortedMap.

So the sequenced interfaces were slotted into the middle of both trees, as new parents of existing interfaces, using default methods so that old implementations kept compiling in almost every case. Even here, the Map tree stays separate: SequencedMap extends Map, not SequencedCollection.

6Follow-up questions

Is Iterable part of the Collections Framework?

It lives in java.lang rather than java.util, because the for-each loop depends on it. Collection extends it, so every collection is iterable, but many classes outside the framework, such as a Path or a custom result set, implement Iterable without being collections.

Why is values() a Collection but keySet() a Set?

Keys in a map are unique, so their view can promise set semantics. Values can repeat, as when two products both have a price of 10, so values() can only promise a plain Collection with duplicates allowed.

Where does Collections, with an s, fit?

It is not part of the hierarchy at all. java.util.Collections is a utility class of static methods, such as sort, unmodifiableList and synchronizedMap, that work on the interfaces.

7Conclusion

In this answer, we walked down the Collection tree from Iterable through List, Set and Queue, with Deque, SortedSet and NavigableSet below them, and then looked at the separate Map tree with SortedMap and NavigableMap. Map stays apart because a mapping of keys to values cannot honour the meaning of add or contains on a collection, so it offers keySet, values and entrySet as views. Java 21 then added SequencedCollection, SequencedSet and SequencedMap into both trees to give ordered collections a common type.

What to say in the interviewAbout 80 seconds aloud

Open with

The framework has two trees. On one side, Iterable is the root, and Collection extends it with the shared operations like size, contains, add and remove. Below Collection there are List, which is ordered with index access and duplicates, Set, which has no duplicates, and Queue for holding elements before processing, with Deque extending Queue for both ends.

Then, if they want more

SortedSet and NavigableSet extend Set, and TreeSet implements them. On the other side is Map, with SortedMap and NavigableMap below it, implemented by HashMap, LinkedHashMap and TreeMap. Map does not extend Collection because its contract is different: it is a lookup from keys to values.

If it were a Collection, add of one element or contains of an object would be ambiguous, whether they mean the key, the value or the pair. So instead Map gives us three live views: keySet, values and entrySet. Removing through a view removes the entry, but adding through keySet is not supported, since there would be no value.

In Java 21, the sequenced interfaces were added into both trees: SequencedCollection is now a parent of List and Deque, SequencedSet covers LinkedHashSet and sorted sets, and SequencedMap covers LinkedHashMap and sorted maps, giving them getFirst, getLast and reversed in one common type.

About this answer

Last updated
12 November 2026
Versions it names
Java 21
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Describe the main interfaces of the Collections Framework and where Map fits. Why does...": https://scrivio-interview-library.netlify.app/java/collections-overview/64f1827642/