IdentityHashMap hashCode() in Java

hashCode(): This method is available in java.util.IdentityHashMap class of Java.

Syntax:

int java.util.IdentityHashMap.hashCode()

This method 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.

Parameters: NA

Returns: the hash code value for this map.

Exceptions: NA

Approach

Java

import java.util.IdentityHashMap;

public class IdentityHashMaphashCode {

    public static void main(String args[]) {

        IdentityHashMap<String, Integer> identityHashMap =
new IdentityHashMap<String, Integer>();

        identityHashMap.put("Java", 1);
        identityHashMap.put("Hello", 2);

        System.out.println(identityHashMap.hashCode());

    }

}

Output:

-795248393


No comments:

Post a Comment