Java hashCode()方法
hashCode()方法
Java中String类方法hashCode()用于将字符串转换为哈希码的值。hashCode()语法如下:
public int hashCode()
hashCode()参数
参数 | 描述 |
---|---|
无 | - |
hashCode()返回值
字符串的哈希码值。
hashCode()实例代码
下面实例代码,使用hashCode()方法,将字符串转换为哈希码值:
public class test {
public static void main(String[] args) {
String x = "笨鸟工具,x1y1z1.com";
int hashcode = x.hashCode();
System.out.println(hashcode);
}
}
代码运行后,得到输出值为:
685676190
免责声明:内容仅供参考,不保证正确性。