IdentityHashMap keySet Example
IdentityHashMap class keySet example. This example shows you how to use keySet method.
IdentityHashMap class keySet example. public Set keySet() Returns an identity-based set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa.
Here is the code
/**
* @ # KeySet.java
* A class repersenting use to KeySet method
* of IdentityHashMap class in java.util package
* version 26 May 2008
* author Rose India
*/
import java.util.*;
public class KeySet {
public static void main(String args[]) {
IdentityHashMap map = new IdentityHashMap();
//Add the mapping into the map
map.put(1, "A");
map.put(2, "A");
map.put(3, "B");
System.out.println("All key of the map") ;
Set set =map.keySet();
Iterator i = set.iterator();
while (i.hasNext()) {
System.out.println(i.next());
}
}
} |
|