Facebook Page Twitter Page LinkedIn Page
× Java.lang Package Classes


The java.lang.Boolean.hashCode() method is used to return 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 below example, the java.lang.Boolean.hashCode() method is used to return 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 = new Boolean(true);
    Boolean b2 = new Boolean(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