GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Python Technologies
  • Databases
  • Computer Programming
  • Web Development
  • Java Technologies
  • Computer Science
  • Mobile Development
  • Big Data & Analytics
  • Microsoft Technologies
  • DevOps
  • Latest Technologies
  • Machine Learning
  • Digital Marketing
  • Software Quality

This view

  • Original page
  • New address

GeezerVison is showing www.tutorialspoint.com — Java - Enum hashCode() method

java package tutorial
  • Java.lang - Home
  • Java.lang - Boolean
  • Java.lang - Byte
  • Java.lang - Character
  • Java.lang - Character.Subset
  • Java.lang - Character.UnicodeBlock
  • Java.lang - Class
  • Java.lang - ClassLoader
  • Java.lang - Compiler
  • Java.lang - Double
  • Java.lang - Enum
  • Java.lang - Float
  • Java.lang - InheritableThreadLocal
  • Java.lang - Integer
  • Java.lang - Long
  • Java.lang - Math
  • Java.lang - Number
  • Java.lang - Object
  • Java.lang - Package
  • Java.lang - Process
  • Java.lang - ProcessBuilder
  • Java.lang - Runtime
  • Java.lang - RuntimePermission
  • Java.lang - SecurityManager
  • Java.lang - Short
  • Java.lang - StackTraceElement
  • Java.lang - StrictMath
  • Java.lang - String
  • Java.lang - StringBuffer
  • Java.lang - StringBuilder
  • Java.lang - System
  • Java.lang - Thread
  • Java.lang - ThreadGroup
  • Java.lang - ThreadLocal
  • Java.lang - Throwable
  • Java.lang - Void
  • Java.lang - Interfaces
  • Java.lang - Errors
  • Java.lang - Exceptions
  • Java.lang Package Useful Resources
  • Java.lang - Useful Resources
  • Java.lang - Discussion
Selected Reading
  • UPSC IAS Exams Notes
  • Developer's Best Practices
  • Questions and Answers
  • Online Resume Builder
  • HR Interview Questions
  • Computer Glossary
  • Who is Who

Java - Enum hashCode() method



Previous
Quiz
Next

Description

The Java Enum hashCode() method returns a hash code for this enum constant.

Declaration

Following is the declaration for java.lang.Enum.hashCode() method

public final int hashCode()

Parameters

NA

Return Value

This method returns a hash code for this enum constant.

Exception

NA

Getting HashCode for an enum Example

The following example shows the usage of hashCode() method for an enum.

package com.tutorialspoint;

// enum showing programming languages
enum Language {
   C, Java, PHP;
}

public class EnumDemo {

   public static void main(String args[]) {

      // returns the name and hashCode of this enum constant
      System.out.print("Programming in " + Language.C.toString());      
      System.out.println(", Hashcode = " + Language.C.hashCode()); 
      System.out.print("Programming in " + Language.Java.toString());  
      System.out.println(", Hashcode = " + Language.Java.hashCode()); 
      System.out.print("Programming in " + Language.PHP.toString());  
      System.out.println(", Hashcode = " + Language.PHP.hashCode());    
   }
} 

Let us compile and run the above program, this will produce the following result −

Programming in C, Hashcode = 745160567
Programming in Java, Hashcode = 610984013
Programming in PHP, Hashcode = 1644443712

Getting HashCode for an enum Example

The following example shows the another usage of hashCode() method for a different enum.

package com.tutorialspoint;

// enum showing topics covered under Tutorials
enum Tutorials {  
   Java, HTML, Python; 
} 
 
public class EnumDemo { 

   public static void main(String args[]) {
 
      Tutorials t1, t2, t3; 
    
      t1 = Tutorials.Java; 
      t2 = Tutorials.HTML; 
      t3 = Tutorials.Python; 
    
      System.out.print("Programming in " + t1.toString());      
      System.out.println(", Hashcode = " + t1.hashCode()); 
      System.out.print("Programming in " + t2.toString());  
      System.out.println(", Hashcode = " + t2.hashCode()); 
      System.out.print("Programming in " + t3.toString());  
      System.out.println(", Hashcode = " + t3.hashCode());
   } 
} 

Let us compile and run the above program, this will produce the following result −

Programming in Java, Hashcode = 745160567
Programming in HTML, Hashcode = 610984013
Programming in Python, Hashcode = 1644443712
java_lang_enum.htm
Tutorix - AI Tutor
Previous Quiz Next
Advertisements
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.