Wednesday, January 21, 2026
HomeLanguagesJavaBoolean hashCode() method in Java with examples

Boolean hashCode() method in Java with examples

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
RELATED ARTICLES

Most Popular

Dominic
32475 POSTS0 COMMENTS
Milvus
119 POSTS0 COMMENTS
Nango Kala
6847 POSTS0 COMMENTS
Nicole Veronica
11977 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12064 POSTS0 COMMENTS
Shaida Kate Naidoo
6986 POSTS0 COMMENTS
Ted Musemwa
7220 POSTS0 COMMENTS
Thapelo Manthata
6933 POSTS0 COMMENTS
Umr Jansen
6912 POSTS0 COMMENTS