- Java.lang 包类
- Java.lang - 首页
- 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 包其他
- Java.lang - 接口
- Java.lang - 错误
- Java.lang - 异常
- Java.lang 包有用资源
- Java.lang - 有用资源
- Java.lang - 讨论
Java - 枚举 hashCode() 方法
描述
Java Enum hashCode() 方法返回此枚举常量的哈希码。
声明
以下是 java.lang.Enum.hashCode() 方法的声明
public final int hashCode()
参数
无
返回值
此方法返回此枚举常量的哈希码。
异常
无
获取枚举的哈希码示例
以下示例演示了枚举中 hashCode() 方法的使用。
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()); } }
让我们编译并运行以上程序,这将产生以下结果:
Programming in C, Hashcode = 745160567 Programming in Java, Hashcode = 610984013 Programming in PHP, Hashcode = 1644443712
获取枚举的哈希码示例
以下示例演示了另一个枚举中 hashCode() 方法的使用。
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()); } }
让我们编译并运行以上程序,这将产生以下结果:
Programming in Java, Hashcode = 745160567 Programming in HTML, Hashcode = 610984013 Programming in Python, Hashcode = 1644443712
java_lang_enum.htm
广告