WeakHashMap size Example
WeakHashMap class values example. This example shows you how to use values method.
WeakHashMap class size example.public int size() Returns the number of key-value mappings in this map. This result is a snapshot, and may not reflect unprocessed entries that will be removed before next attempted access because they are no longer referenced.
Here is the code
/**
* @ # Size.java
* A class repersenting use to Size method
* of WeakHashMap class in java.util package
* version 22 May 2008
* author Rose India
*/
import java.util.*;
public class Size {
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);
System.out.println("Size of the map " + map.size());
}
} |
Output
map = {4=D, 3=C, 2=B, 1=A}
Size of the map 4 |
|