Java Data Type Tutorial - Java Boolean.hashCode()








Syntax

Boolean.hashCode() has the following syntax.

public int hashCode()

Example

In the following code shows how to use Boolean.hashCode() method.

public class Main {
   public static void main(String[] args) {
      Boolean b1 = new Boolean(true);
      Boolean b2 = new Boolean(false);
/* w  w  w . jav  a2s  . c om*/
      // assign the hash code of b1, b2 to i1, i2
      int i1 = b1.hashCode();
      int i2 = b2.hashCode();

      System.out.println("Hash code of " + b1 + " is "  +i1);
      System.out.println("Hash code of " + b2 + " is "  +i2);
   }
}

The code above generates the following result.