TreeMap hashCode() in Java

hashCode(): This method is available in java.util.TreeMap 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.TreeMap;

public class TreeMaphashCode {
    public static void main(String[] args) {

        TreeMap<Integer, String> treeMap =
new TreeMap<Integer, String>();

        treeMap.put(2, "Hello");
        treeMap.put(11, "Java");
        treeMap.put(23, "Program");
        treeMap.put(6, "C++");
        treeMap.put(25, "Program");

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

    }
}

Output:

-1512459058


No comments:

Post a Comment