Java BooleanObject hashCode()方法及示例
布尔类的 hashCode() 方法是一个内置的方法,用于返回布尔对象对应的 int 哈希码值。
语法
BooleanObject.hashCode()
返回类型: 它返回一个与布尔对象对应的 int 哈希码值。如果布尔对象存储的值是 true ,则返回 1231 。如果布尔对象存储的是 假值 ,则返回 1237 。
下面是hashCode()方法在Java中的实现。
程序1 :
// java code to demonstrate// Boolean hashCode() method class GFG { public static void main(String[] args) { // creating Boolean object Boolean b = new Boolean(true); // hashCode method of Boolean class int output = b.hashCode(); // printing the output System.out.println(output); }}
输出:
1231
程序2
// java code to demonstrate // Boolean hashCode() method class GFG { public static void main(String[] args) { // creating Boolean object Boolean b = new Boolean(false); // hashCode method of Boolean class int output = b.hashCode(); // printing the output System.out.println(output); }}
输出:
1237
