IdentityHashMap hashCode() Method in Java
The hashCode()
method in IdentityHashMap
class in Java returns the hash code value for the specified object. The hash code value is calculated based on the memory address of the object rather than its contents.
Syntax:
public int hashCode()
Example:
IdentityHashMap<String, Integer> map = new IdentityHashMap<>();
map.put("one", 1);
map.put("two", 2);
map.put("three", 3);
int hashCode = map.hashCode();
System.out.println("Hash code of map: " + hashCode);
Output:
Hash code of map: 366712642
Note: The hashCode()
method in IdentityHashMap
is inherited from the Object
class and is overridden to provide the hash code based on the memory address of the object.