Sunday 22 June 2014

Why Map interface doesn't extend Collection interface?

          In previous post, discussed about collection hierarchy and what are the collection framework interfaces and classes. In the current post, will have discussion about why map interface doesn't inherits Collection interface as we know that map is also a part of Collection framework.     

As we know that Map is key and value pair, but collection is a "group of elements". In Map doesn't have elements, instead of elements it has key and value pair. It doesn't fit in to Collection concept.    

Map interface and it’s implementations are part of Collections Framework, Map are not collections and collections are not Map. Hence it doesn’t make sense for Map to extend Collection or vice versa.

Related Posts:--
1) How HashMap works internally in Java?
2) Internal Implementation of TreeMap in Java
3) Internal implementation of ArrayList in Java
4) Collection Interview Questions and Answers in Java
5) Internal Implementation of LinkedList in Java
6) Collection Hierarchy in Java

No comments:

Post a Comment