bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths

Loading lesson path

Learn/Java/Java Reference
Java•Java Reference

Java String hashCode() Method

❮ String Methods

Example

String myStr = "Hello";
System.out.println(myStr.hashCode());

Definition and Usage

The hashCode() method returns the hash code of a string.

The hash code for a String object is computed like this:

s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]

where s[i] is the ith character of the string, n is the length of the string, and ^ indicates exponentiation.

Syntax

public int hashCode()

Parameter Values

None.

Technical Details

Returns:An int value, representing the hash code of the string

Previous

Java String getChars() Method

Next

Java String indexOf() Method