温馨提示×

java获取hash值的方法是什么

小亿
160
2024-06-03 17:39:07
栏目: 编程语言
Java开发者专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

在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()方法来获取其哈希值,并将其打印输出。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:java生成hash值的方法是什么

0