EnumSet hashCode() in Java

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

Syntax:

int java.util.AbstractSet.hashCode()

This method returns the hash code value for this set.

Note: The hash code of a set is defined to be the sum of the hash codes of the elements in the set, where the hash code of a null element is defined to be zero.

Parameters: NA

Returns: the hash code value for this set.

Exception: NA

Approach

Java

import java.util.EnumSet;

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

    public static void main(String[] args) {

        EnumSet<Colour> enumSet = EnumSet.allOf(Colour.class);

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

    }
}

Output:

631065263


No comments:

Post a Comment