欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

java字符串的哈希码_获取Java中字符串的哈希码

发布时间:2024/9/27 37 豆豆
生活随笔 收集整理的这篇文章主要介绍了 java字符串的哈希码_获取Java中字符串的哈希码 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

该hashCode()方法用于获取字符串的哈希码。此方法不接受任何参数,因为它是默认方法,并且它返回哈希码值。

hashCode()给出了演示Java方法的程序,如下所示:

示例import java.io.*;

public class Demo {

public static void main(String args[]) {

String str = new String("The sky is blue");

System.out.println("The string is: " + str);

System.out.println("The Hashcode for the string is: " + str.hashCode());

}

}

输出结果The string is: The sky is blue

The Hashcode for the string is: -729257918

现在让我们了解上面的程序。

字符串str被定义。然后,使用该hashCode()方法打印字符串,并打印其HashCode 。演示此代码段如下:String str = new String("The sky is blue");

System.out.println("The string is: " + str);

System.out.println("The Hashcode for the string is: " + str.hashCode());

总结

以上是生活随笔为你收集整理的java字符串的哈希码_获取Java中字符串的哈希码的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。