Java String Hashcode
# Java hashCode() Method
[Java String Class](#)
* * *
The hashCode() method is used to return the hash code of a string.
The hash code for a string object is calculated according to the following formula:
s*31^(n-1) + s*31^(n-2) + ... + s
Using int arithmetic, where s is the ASCII code of the i-th character of the string, n is the length of the string, and ^ denotes exponentiation. The hash value of an empty string is 0.
### Syntax
public int hashCode()
### Parameters
* None.
### Return Value
Returns the hash code value of the object.
### Example
## Example
public class Test {
public static void main(String args[]){
String Str =new String("www.");
System.out.println("The hash code of the string is :"+ Str.hashCode());
}
}
The output of the above program is:
The hash code of the string is :321005537
* * Java String Class](#)
YouTip