1.

Why Does Map Interface Not Extend The Collection Interface In The Java Collections Framework?

Answer»

The map interface is not compatible with the Collection interface. Because Map REQUIRES key as well as value, for example: if we want to add key-value pair so we will use PUT(OBJECT key , Object value). There are two parameters required to add an element to HashMap object. In Collection interface add(Object o) has only ONE parameter.
The other reasons are Map supports valueSet, keySet as well as other suitable methods which have just different VIEWS from the Collection interface.

The map interface is not compatible with the Collection interface. Because Map requires key as well as value, for example: if we want to add key-value pair so we will use put(Object key , Object value). There are two parameters required to add an element to HashMap object. In Collection interface add(Object o) has only one parameter.
The other reasons are Map supports valueSet, keySet as well as other suitable methods which have just different views from the Collection interface.



Discussion

No Comment Found