Why Map interface not extend Collection interface

Why Map interface not extend Collection interface

Answer: Probably both could have been designed to re-use same common interface but some of the methods they implement are incompatible below are differences:

CollectionMap
Collection interface represents group of objects known as its elementsMap interface is also an object which maps keys to values
Collection interface has used to pass and work around collections of objects wherever maximum generality is desired Where on Map interface each key could map to at least one value
It has been designed to work on objectIt has been designed to work on object with key value pair
Methods they implements are incompatible. For example: Collection.remove(Object) – This removes object as an element.Method implementation is incompatible. For example: Map.remove(Object) – This removes object by its  key not by entry.

 

Leave a Reply

Your email address will not be published. Required fields are marked *