在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值的方法是什么