EnumMap hashCode() in Java

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

Syntax:

int java.util.EnumMap.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.

Parameters: NA

Returns: the hash code value for this map.

Exceptions: NA

Approach

Java

import java.util.EnumMap;

public class EnumMaphashCode {

    public enum Colour {
        RED, GREEN, YELLOW, ORANGE
    };

    public static void main(String[] args) {

        EnumMap<Colour, String> enumMap =
new EnumMap<Colour, String>(Colour.class);

        enumMap.put(Colour.RED, "Red");
        enumMap.put(Colour.GREEN, "Green");

        enumMap.put(Colour.YELLOW, "Yellow");
        enumMap.put(Colour.ORANGE, "Orange");

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

    }
}

Output:

1625820376


No comments:

Post a Comment