Java Data Type Tutorial - Java Enum.hashCode()








Syntax

Enum.hashCode() has the following syntax.

public final int hashCode()

Example

In the following code shows how to use Enum.hashCode() method.

//w  ww.j  a v  a 2  s . c  om
enum Tutorial {
   C, Java, PHP;
}

public class Main {

   public static void main(String args[]) {
       
     // returns the name and hashCode of this enum constant
     System.out.print("Programming in " + Tutorial.C.toString());      
     System.out.println(", Hashcode = " + Tutorial.C.hashCode()); 
     System.out.print("Programming in " + Tutorial.Java.toString());  
     System.out.println(", Hashcode = " + Tutorial.Java.hashCode()); 
     System.out.print("Programming in " + Tutorial.PHP.toString());  
     System.out.println(", Hashcode = " + Tutorial.PHP.hashCode());    
   }
}

The code above generates the following result.