Java hashCode () method
hashCode () method returns a hash code string.
String object hash code based on the following formula:
s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
Using int arithmetic, where s [i] is the i-th character of the string, n is the length of the string, and ^ indicates exponentiation. Empty string hash value is 0.
grammar
public int hashCode()
parameter
- no.
return value
Returns the hash code value for the object.
Examples
public class Test { public static void main(String args[]) { String Str = new String("www.w3big.com"); System.out.println("字符串的哈希码为 :" + Str.hashCode() ); } }
The above program execution results:
字符串的哈希码为 :321005537