Java Character hashCode() 方法

2024年11月6日 | 阅读 4 分钟

Character 类的 hashCode() 方法通常返回给定字符的哈希码。该方法的结果类似于调用 charValue() 方法的结果。

语法

参数

不适用。

返回值

Character 类的 hashCode() 方法返回给定字符的哈希码。

示例 1

输出

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

示例 2

输出

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

示例 3

输出

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) 方法

Character 类的 hashCode(char value) 方法通常返回给定 char 值的哈希码类型的值。该方法的结果类似于 Character.hashCode() 方法的结果。

语法

参数

value: 需要返回哈希码的 char 值。

返回值

hashCode(char value) 方法返回给定 char 值的哈希码类型的值。

示例 4

输出

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

示例 5

输出

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