bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/Java/Java Reference
Java•Java Reference

Java String hashCode() Method

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind Java String hashCode() Method?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

___ myStr = "Hello";
3Order

Put the learning moves in the order that makes the concept easiest to apply.

The hashCode() method returns the hash code of a string.
Definition and Usage
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