The java.util.Map interface is the root interface of the map hierarchy. Interestingly, it doesn’t extend the familiar java.util.Collection interface. It facilitates storage, retrieval, and manipulation of key-value pairs.
The popular implementations of Map are java.util.HashMap andjava.util.TreeMap. The HashMap facilitates easy insertion, deletion, and retrieval of elements. On the other hand, TreeMap is a neat alternative to traverse the keys of a map in a sorted order.
// MapDemo.javaimport java.util.*;/** Demonstrates the use of popular java.util.Map implementations. */public class MapDemo { /** The hash map to add data. */ private HashMap hashMap; /** The tree map to sort data. */ private TreeMap treeMap; /** Starts the demo. */ public void startDemo() { // Initialize the hash map hashMap = new HashMap(); hashMap.put(