Java String hashCode() method

tutorial and example
tutorial and example

Java String hashCode() method returns hash code for current String.

hash code for string object is computed as

Using int arithmetic, where s[i] is the ith character of the string, n is the length of the string, and ^ indicates exponentiation. (The hash value of the empty string is zero.)

Syntax:

Return:  an int datatype i.e. hashcode of the String.

Java String hashCode() example 1:

Output:

Java String hashCode() example 2: Two String having same hash code

Output:

Java String hashCode() example 3:

Output:

Java String hashCode() example 4:

Output: