Guava Chars.hashCode()方法与实例
Chars.hashCode()是Guava库中Chars类的一个方法,用于返回一个char值的哈希代码。hashCode是一个唯一的整数值,是由编译器为一个对象计算的。如果对象的值没有变化,它将保持不变。
语法:
public static int hashCode(char value)
参数: 这个方法需要一个强制性的参数 value ,这个参数是一个要找到hashCode的char值。
返回值: 该方法返回一个整数值,即指定值的散列代码。
以下程序说明了上述方法的使用。
示例1:
// Java code to show implementation of// Guava's Chars.hashCode() method import com.google.common.primitives.Chars;import java.util.Arrays; class GFG { // Driver's code public static void main(String[] args) { // Using Chars.hashCode() method to // get the hash code for value System.out.println("HashCode value of y: " + Chars.hashCode('y')); }}
输出:
HashCode value of y: 121
示例2:
// Java code to show implementation of// Guava's Chars.hashCode() method import com.google.common.primitives.Chars;import java.util.Arrays; class GFG { // Driver's code public static void main(String[] args) { // Using Chars.hashCode() method to // get the hash code for value System.out.println("HashCode value of J: " + Chars.hashCode('J')); }}
输出:
HashCode value of J: 74
参考: https://google.github.io/guava/releases/23.0/api/docs/com/google/common/primitives/Chars.html#hashCode-char-
