温馨提示×

java获取hash值的方法是什么

小亿
86
2024-06-03 17:39:07
栏目: 编程语言

在Java中,可以通过hashCode()方法来获取对象的哈希值。具体方法如下:

public class HashCodeExample {
    public static void main(String[] args) {
        String str = "Hello";
        int hashCode = str.hashCode();

        System.out.println("Hash code of the string is: " + hashCode);
    }
}

在上面的例子中,我们创建了一个字符串对象"Hello",然后调用其hashCode()方法来获取其哈希值,并将其打印输出。

0