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.


//  ww w.j av  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.





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable