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中字符串的哈希码的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: construct2 ajax,Cons
- 下一篇: java在实际应用_Java应用程序如何