IdentityHashMap hashCode Example
IdentityHashMap class hashCode example. This example shows you how to use hashCode method.
IdentityHashMap class hashCode example. public int hashCode() Returns the hash code value for this map. The hash code of a map is defined to be the sum of the hash codes of each entry in the map's entrySet() view.
Here is the code
/**
* @ # HashCode.java
* A class repersenting use to hashCode method
* of IdentityHashMap class in java.util package
* version 26 May 2008
* author Rose India
*/
import java.util.*;
public class HashCode {
public static void main(String args[]){
IdentityHashMap map = new IdentityHashMap();
IdentityHashMap map1 = new IdentityHashMap();
//Add the mapping into the map
map.put(1, "A");
map.put(2, "A");
map.put(3, "B");
map1.put(1, "A");
map1.put(2, "A");
map1.put(3, "B");
System.out.println("Hashcode " + map.hashCode());
System.out.println("Hashcode " + map1.hashCode());
System.out.println("Hashcode " + map.clone().hashCode());
}
} |
Output
Hashcode 33103390
Hashcode 33103390
Hashcode 33103390 |
|