Guava – Booleans.hashCode()方法及示例
Booleans.hashCode() 是Guava库中Booleans类的一个方法,用于返回一个布尔值的哈希代码。hashCode是一个唯一的整数值,是由编译器为一个对象计算的。如果对象的值没有变化,它就保持不变。
语法:
public static int hashCode(boolean value)
参数: 这个方法需要一个强制性的参数值,它是一个布尔值,要找到这个值的hashCode。
返回值: 该方法返回一个整数值,即指定值的哈希代码。
下面的程序说明了上述方法的使用。
例子-1 :
// Java code to show implementation of// Guava's Booleans.hashCode() methodimport com.google.common.primitives.Booleans;import java.util.Arrays; class GFG { // Driver's code public static void main(String[] args) { // Using Booleans.hashCode() method to // get the hash code for value System.out.println(Booleans.hashCode(true)); }}
输出:
1231
例2 :
// Java code to show implementation of// Guava's Booleans.hashCode() methodimport com.google.common.primitives.Booleans;import java.util.Arrays; class GFG { // Driver's code public static void main(String[] args) { // Using Booleans.hashCode() method to // get the hash code for value System.out.println(Booleans.hashCode(false)); }}
输出:
1237
参考资料:
https://google.github.io/guava/releases/20.0/api/docs/com/google/common/primitives/Booleans.html#hashCode-boolean-
