Returns true if this map contains a mapping for the specified key.
Program
package com.candidjava;
import java.util.Map;
import java.util.WeakHashMap;
/*
* @author : Mohan
* @description : The containsKey(Object key) method is used to return true if this map contains a mapping for the specified key.
*/
public class WeakHashMapContainsKey {
public static void main(String[] args) {
Map weakHashMap = new WeakHashMap();
weakHashMap.put("1", "anandh");
weakHashMap.put("2", "hari");
weakHashMap.put("3", "vinoth");
weakHashMap.put("4", "kamal");
weakHashMap.put("5", "karthic");
System.out.println("Checking value for key 1 ="+ weakHashMap.containsKey("1"));
}
}
Output
Checking value for key 1 =true
Explanation
public boolean containsKey(Object key)
Returns true if this map contains a mapping for the specified key.
Specified by:
containsKey in interface Map
Overrides:
containsKey in class AbstractMap
Parameters:
key - The key whose presence in this map is to be tested
Returns:
true if there is a mapping for key; false otherwise