WeakHashMap containsKey Example
WeakHashMap class containsKey example. This example shows you how to use containsKey method.
WeakHashMap class containsKey example.public boolean containsKey(Object key) Returns true if this map contains a mapping for the specified key.
Here is the code
/**
* @ # ContainsKey.java
* A class repersenting use to containsKey method
* of WeakHashMap class in java.util package
* version 22 May 2008
* author Rose India
*/
import java.util.*;
public class ContainsKey {
public static void main(String args[]) {
WeakHashMap map = new WeakHashMap();
map.put(1, "A");
map.put(2, "B");
map.put(3, "C");
map.put(4, "D");
System.out.println("map = " + map);
//Returns true if this map contains a mapping
System.out.println(map.containsKey(1));
}
} |
Output
map = {4=D, 3=C, 2=B, 1=A}
true |
|