Java Enum hashCode() Method

The hashCode() method of Enum class returns a hash code for this enum.

Syntax

Parameters

NA

Override

The hashCode() method of Enum class overrides the hashCode() method of Object class.

Return Value

ThehashCode() method returns a hash code for this enum.

Example 1

Output:

Hash code for winter = 248609774
Hash code for summer = 708049632
Hash code for spring = 1887400018
Hash code for rainy = 285377351
Hash code for autumn = 344560770

Example 2

Output:

red = 1338823963
green = 1156060786
blue = 1612799726
orange = 1286084959

Example 3

Output:

hash code of red =708049632
hash code of Red =1887400018
hash code of REd =285377351
hash code of RED =344560770

708049632 is greater.