此方法返回此字符串的hashCode。字符串对象的hashCode计算为-
s[0]*31^(n - 1) + s[1]*31^(n - 2) + ... + s[n - 1]
使用int算术,其中s [i]是字符串的第i个字符,n是字符串的长度,^表示幂。 (空字符串的哈希值为零。)
public int hashCode()
import java.io.*; public class Test { public static void main(String args[]) { String Str=new String("Welcome to Learnfk.com"); System.out.println("Hashcode for Str :" + Str.hashCode() ); } }
这将产生以下输出-
Hashcode for Str :1186874997
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)