Javatpoint Logo
Javatpoint Logo

Java Character hashCode() Method

The hashCode() method of Character class generally returns the hash code for the given character. The result of the given method is similar to the result of invoking the charValue() method.

Syntax

Parameter

N.A.

Return Value

The hashCode() method of Character class returns the hash code for the given character.

Example 1

Test it Now

Output:

The hashcode for the first character 'A' is given as: 65
The hashcode for the second character 'a' is given as: 97

Example 2

Test it Now

Output:

The hash code for 'M' is given as: 77
The hash code for 'N is given as:  78
The hash code for 'O' is given as: 79
The hash code for 'a' is given as: 97
The hash code for 'b' is given as: 98
The hash code for 'c' is given as: 99

Example 3

Test it Now

Output:

The hash code for '1' is given as: 49
The hash code for '2' is given as:  50
The hash code for '3' is given as: 51

Java Character hashCode(char value) Method

The hashCode(char value) method of Character class generally returns a value of type hash code for a given char value. The result of the given method is similar to the result of Character.hashCode() method.

Syntax

Parameter

value: It is the char value for which there is a need to return a hash code.

Return Value

The hashCode(char value)method returns a value of type hash code for the given char value.

Example 4

Test it Now

Output:

The hash code for the first character is given as: 68
The hash code for the second character is given as:100

Example 5

Test it Now

Output:

The hash code for the first character is given as: 49
The hash code for the second character is given as:51
The hash code for the second character is given as:53
Next TopicJava Character



Please Share

facebook twitter google plus pinterest