Java String hashCode() method example

HQ » Java Tutorial » java.lang » String » hashCode() method example
Java String hashCode() method example 2018-02-19T12:51:40+00:00

java.lang.String hashCode()

Description :

This java tutorial shows how to use the hashCode() method of java.lang.String class. This method returns an int datatype which corresponds to the hash code of the string. The following formula is being used in the computation:

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

Method Syntax :

public int hashCode()

Parameter Input :

  • None

Method Returns :

This method returns an int datatype which corresponds to the hash code of the String.

Java Code Example :

This example source code demonstrates the use of hashCode() method of String class. Basically this source code just prints the Hash Code equivalent of our String.

Sample Output :

Running the hashCode() method example source code of java.lang.String class will give you the following output

string hashcode method example

string hashcode method example

Suggested Reading List :

References :

 

Contact Info

Singapore

Our Goal

JavaTutorialHQ aims to to be The Ultimate Guide on Java with hundreds of examples from basic to advance Topics.

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close