Curriculum
Course: Java Basic
Login

Curriculum

Java Basic

Java Home

0/1

Java Introduction

0/1

Java Get Started

0/1

Java Syntax

0/1

Java Comments

0/1

Java Type Casting

0/1

Java Operators

0/1

Java Booleans

0/1

Java Switch

0/1

Java Break / Continue

0/1

Java Errors and Exception

0/1
Text lesson

hashCode()

Example

“Retrieve the hash code of a string.”

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 as follows:

 

s[0]*31^(n1) + s[1]*31^(n2) + + s[n1]

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 integer value representing the hash code of the string