IdentityHashMap类hashCode()方法hashCode()方法在java.util包中可用。
hashCode()方法用于返回此IdentityHashMap的哈希码值。
hashCode()方法是一种非静态方法,仅可通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。
hashCode()方法在返回哈希码时不会引发异常。
语法:public int hashCode();
参数:它不接受任何参数。
返回值:
方法的返回类型为int,它获取此IdentityHashMap的哈希码值。
示例//Java程序演示示例
//hashCode()IdentityHashMap的int方法的说明
import java.util.*;
public class HashCodeOfIdentityHashMap {
public static void main(String[] args) {
//实例化一个IdentityHashMap对象
Map map = new IdentityHashMap ();
//通过使用put()方法是添加
//IdentityHashMap中的键值对
map.put(10, "C");
map.put(20, "C++");
map.put(50, "JAVA");
map.put(40, "PHP");
map.put(30, "SFDC");
//显示IdentityHashMap-
System.out.println("IdentityHashMap: " + map);
//通过使用hashCode()方法就是返回
//此IdentityHashMap的哈希码值
int hc = map.hashCode();
//显示哈希码
System.out.print("map.hashCode(): ");
System.out.println(hc);
}
}
输出结果IdentityHashMap: {20=C++, 40=PHP, 50=JAVA, 30=SFDC, 10=C}
map.hashCode(): -693690910