| 1. |
What is a Map interface, why it’s not a part of collection framework and when to use? |
|
Answer» A map is an object that maps keys to VALUES. The map works on key-value pair principal. A map doesn't allow to contain duplicate keys. Each key can map to at most one value. HashMap, TreeMap, ConcurentHashMap are the implementation of the map. The map has three kind of collection like key, values and key values and it doesn’t IMPLEMENT the collection interface that is the reason the Map interface doesn’t fall in the collection HIERARCHY. The order of the map depends on the specific implementation classes. Code Snippet: Map map = new HashMap();. The best use case is when we need to SPECIFY the pairing between the object and store accordingly. |
|