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);
/*from w  w  w . j  a v  a 2  s .  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.





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable