Skip to content
Related Articles

Related Articles

Improve Article
Boolean hashCode() method in Java with examples
  • Last Updated : 08 Oct, 2018

The hashCode() method of Boolean class is a built in method to return a int hashcode value corresponding to the Boolean object.

Syntax

BooleanObject.hashCode()

Return Type: It returns a int hashcode value corresponding to the Boolean object. It returns 1231 if the Boolean object stores the value true. It returns 1237 if the Boolean object stores the value false.

Below is the implementation of hashCode() method in Java:

Program 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);
    }
}
Output:
1231

Program 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);
    }
}
Output:
1237

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :