containsKey(Object): This method is available in java.util.WeakHashMap class of Java.
Syntax:
boolean java.util.WeakHashMap.containsKey(Object key)
This method takes one argument. This method returns true if this map contains a mapping for the specified key.
Parameters: One parameter is required for this method.
key: The key whose presence in this map is to be tested.
Returns: true if there is a mapping for key; false otherwise.
Exceptions: NA
Approach
Java
import java.util.WeakHashMap;public class WeakHashMapcontainsKey {public static void main(String[] args) {WeakHashMap<String, String> weakHashMap =new WeakHashMap<String, String>();weakHashMap.put("Java", "Program");weakHashMap.put("Hello", "World");String key = "Hello";System.out.println(weakHashMap.containsKey(key));}}
Output:
true
No comments:
Post a Comment