获取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 红包祝福语简短10字
18 周六早晨祝福语简短