HashMap hashCode() in Java

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

Syntax:

int java.util.AbstractMap.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.HashMap;

public class HashMaphashCode {
    public static void main(String[] args) {
        HashMap<String, Integer> hashMap =
new HashMap<String, Integer>();

        hashMap.put("Hello", 1);
        hashMap.put("World", 2);

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

    }
}

Output:

153375779


No comments:

Post a Comment