获取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());热门推荐
10 香港老妈结婚祝福语简短
11 毕业立体贺卡祝福语简短
12 简短新年年会祝福语
13 评论小品祝福语大全简短
14 恭喜师兄结婚祝福语简短
15 员工集体辞职祝福语简短
16 高中新生祝福语 简短
17 装修祝福语男生搞笑简短
18 生日开业蛋糕祝福语简短