获取 Java 中的整型哈希码
整数的哈希码可以使用 Java 中的 hashCode() 方法获取。此方法不接受任何参数,并返回 Integer 对象的哈希码值。
如下所示,展示了在 Java 中使用 hashCode() 方法的程序
示例
import java.lang.*;
public class Demo {
public static void main(String args[]) {
Integer i = new Integer(60);
System.out.println("The integer value is: " + i);
System.out.println("The Hashcode for the above value is: " + i.hashCode());
}
}输出
The integer value is: 60 The Hashcode for the above value is: 60
现在我们来理解一下上面的程序。
定义了整数 i。然后打印 Integer 值,并使用 hashCode() 方法打印其哈希码。演示此操作的代码片段如下
Integer i = new Integer(60);
System.out.println("The integer value is: " + i);
System.out.println("The Hashcode for the above value is: " + i.hashCode());
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP