The following example shows how to check whether a specified key or value
exists in the Map.
HashMap and Hashtable are two implementations of Map interface.
Hashtable is synchronized where as HashMap is not.
Map provides the following APIs,
public boolean containsKey(Object paramObject);
- Returns true if the Map contains specified key otherwise returns false.
public boolean containsValue(Object paramObject);
- Returns true if the Map contains specified value otherwise returns false.
//Check for value
System.out.println("Map contains value 'TWO' : " + numMap.containsValue("TWO"));
System.out.println("Map contains value 'SIX' : " + numMap.containsValue("SIX"));
}