📌  相关文章
📜  Java番石榴 | Shorts.hashCode() 方法和示例

📅  最后修改于: 2022-05-13 01:55:14.127000             🧑  作者: Mango

Java番石榴 | Shorts.hashCode() 方法和示例

Shorts.hashCode()是 Guava 库中 Shorts 类的一个方法,用于返回一个短值的哈希码。 hashCode 是编译器为对象计算的唯一整数值。如果对象值不变,则保持不变。

句法:

public static int hashCode(short value)

参数:此方法采用强制参数,该参数值是要为其找到 hashCode 的短值。

返回值:此方法返回一个整数值,它是指定值的哈希码。

下面的程序说明了上述方法的使用:

示例 1:

// Java code to show implementation of
// Guava's Shorts.hashCode() method
  
import com.google.common.primitives.Shorts;
import java.util.Arrays;
  
class GFG {
  
    // Driver's code
    public static void main(String[] args)
    {
  
        // Using Shorts.hashCode() method to
        // get the hash code for value
        System.out.println("HashCode value of 15: "
                           + Shorts.hashCode((short)15));
    }
}
输出:
HashCode value of 15: 15

示例 2:

// Java code to show implementation of
// Guava's Shorts.hashCode() method
  
import com.google.common.primitives.Shorts;
import java.util.Arrays;
  
class GFG {
    // Driver's code
    public static void main(String[] args)
    {
        // Using Shorts.hashCode() method to
        // get the hash code for value
        System.out.println("HashCode value of 10: "
                           + Shorts.hashCode((short)10));
    }
}
输出:
HashCode value of 10: 10

参考: https://google.github.io/guava/releases/23.0/api/docs/com/google/common/primitives/Shorts.html#hashCode-short-