Java.util.Hashtable 类

java.util.Hashtable.hashCode() 方法根据定义返回此 Map 的哈希代码值map接口。

语法

public int hashCode()

参数

无需参数。

返回值

返回此哈希表的哈希代码值。

异常

无。

示例:

在示例中下面,java.util.Hashtable.hashCode() 方法返回给定哈希表的哈希代码值。

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //创建哈希表
    Hashtable<Integer, String> Htable = new Hashtable<Integer, String>();

    //填充哈希表
    Htable.put(101, "John");
    Htable.put(102, "Marry");
    Htable.put(103, "Kim");
    Htable.put(104, "Jo");
    Htable.put(105, "Sam");

    //打印哈希表
    System.out.println("Htable contains: " + Htable);   

    //打印哈希表的哈希码
    System.out.print("Hash Code of Htable is: ");
    System.out.print(Htable.hashCode());
  }
}

上述代码的输出将为:

Htable contains: {105=Sam, 104=Jo, 103=Kim, 102=Marry, 101=John}
Hash Code of Htable is: 76589404