Why Map does not extend Collection interface?
--
Collections in any language is an interface that stores similar data type objects and provides an iteration functionality. The common extensions of Collection are List
and Set
.
The Map is a well-known data structure used to store key-value pairs where keys will be unique.
This post was originally posted at https://agrawalsuneet.github.io/blogs/why-map-does-not-extend-collection-interface/ and reposted on Medium on 28th April 2021.
We can take a reference of any language but let’s look at the example of Java for reference as Collection Framework from Java is very popular.
Java has Iterable
interface which is extended by Collection
. The Collection
is further extended by List
, Queue
and Set
which has their different-different implementations but the unique thing notice is that the Map interface doesn’t extend Collection
interface.