Home » Java Boolean hashCode() Method with Examples

Java Boolean hashCode() Method with Examples

by Online Tutorials Library

Java Boolean hashcode() Method

The hashCode() method of Java Boolean class returns the hash code for Boolean.

Overrides:

The hashCode() method of Boolean class overrides the hashCode() method of class Object.

Syntax:

Parameters:

NA

value – is the Boolean value provided to hash.

Return Value:

This method returns a hash code value for this Boolean object.

  • If the object represents true, the result returned is the integer 1231,
  • And if the object represents false, the result returned is the integer 1237.

Example 1

Test it Now

Output:

1. Hash code of true = 1231  2. Hash code of false = 1237  

Example 2

Output:

Enter your age  18  Hash code match i.e. 1231  You are an adult.  You are eligible to vote.  

Example 3

Output:

Q How many days are there in a leap year?  Ans: 366  Answer is right.  

Next TopicJava Boolean

You may also like