WeakHashMap clear Example
WeakHashMap class clear example. This example shows you how to use clear method.
WeakHashMap class clear example.public void clear() Removes all of the mappings from this map. The map will be empty after this call returns.
Here is the code
/**
* @ # Clear.java
* A class repersenting use to clear method
* of WeakHashMap class in java.util package
* version 22 May 2008
* author Rose India
*/
import java.util.*;
public class Clear {
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);
//Removes all of the mappings
map.clear();
System.out.println("map = " + map);
}
} |
Output
map = {4=D, 3=C, 2=B, 1=A}
map = {} |
|