Java Data Type Tutorial - Java Boolean.equals(Object obj)








Syntax

Boolean.equals(Object obj) has the following syntax.

public boolean equals(Object obj)

Example

In the following code shows how to use Boolean.equals(Object obj) method.

public class Main {
   public static void main(String[] args) {
      Boolean b1 = new Boolean(true);
      Boolean b2 = new Boolean(false);
/*www.  j a  v  a 2s.  c o m*/
      // assign the result of equals method on b1, b2 to res
      boolean res = b1.equals(b2);

      System.out.println("b1:" +b1+ " and b2:" +b2+ " are equal is " + res);
   }
}

The code above generates the following result.