Java.lang Package Classes

Java Boolean - hashCode() Method



The java.lang.Boolean.hashCode() method returns a hash code for this Boolean object.

Syntax

public int hashCode()

Parameters

No parameter is required.

Return Value

Returns the integer 1231 if this object represents true; returns the integer 1237 if this object represents false.

Exception

NA.

Example:

In the example below, the java.lang.Boolean.hashCode() method returns a hash code for the given Boolean object.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //creating Boolean objects
    Boolean b1 = true;
    Boolean b2 = false;

    //printing hashcode of the Boolean objects
    System.out.println("hashCode of the b1 is: " + b1.hashCode()); 
    System.out.println("hashCode of the b2 is: " + b2.hashCode());   
  }
}

The output of the above code will be:

hashCode of the b1 is: 1231
hashCode of the b2 is: 1237

❮ Java.lang - Boolean