Java Enum hashCode()方法
java.lang.Enum.hashCode() 方法返回枚举常量的哈希码。
1 语法
public final int hashCode()
2 参数
无
3 返回值
此方法返回枚举常量的哈希码。
4 示例
package com.yiidian;
/**
* 一点教程网: http://www.yiidian.com
*/
/**
* Java Enum hashCode()方法
*/
import java.lang.*;
// 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 = 1569228633
Programming in Java, Hashcode = 778966024
Programming in PHP, Hashcode = 1021653256
热门文章
优秀文章