Open In App

Boolean equals() method in Java with examples

Improve
Improve
Like Article
Like
Save
Share
Report


The equals() method of Boolean class is a built in method of Java which is used check equality of two Boolean object.

Syntax:

BooleanObject.equals(Object ob)

Parameter: It take a parameter ob of type Object as input which is the instance to be compared.

Return Type: The return type is boolean. It returns true if the specified Object ‘ob’ has same value as the ‘BooleanObject’, else it returns false.

Below are programs to illustrate the equals() method of Boolean class:

Program 1:




// Java code to implement
// equals() method of Boolean class
  
class GeeksforGeeks {
  
    // Driver method
    public static void main(String[] args)
    {
  
        // Boolean object
        Boolean a = new Boolean(true);
  
        // Boolean object
        Boolean b = new Boolean(true);
  
        // compare method
        System.out.println(a + " comparing with " + b
                           + " = " + a.equals(b));
    }
}


Output:

true comparing with true = true

Program 2:




// Java code to implement
// equals() method of Java class
  
class GeeksforGeeks {
  
    // Driver method
    public static void main(String[] args)
    {
  
        // Boolean object
        Boolean a = new Boolean(true);
  
        // Boolean object
        Boolean b = new Boolean(false);
  
        // compare method
        System.out.println(a + " comparing with " + b
                           + " = " + a.equals(b));
    }
}


Output:

true comparing with false = false

Program 3:




// Java code to implement
// equals() method of Java class
  
class GeeksforGeeks {
  
    // Driver method
    public static void main(String[] args)
    {
  
        // Boolean object
        Boolean a = new Boolean(false);
  
        // Boolean object
        Boolean b = new Boolean(true);
  
        // compare method
        System.out.println(a + " comparing with " + b
                           + " = " + a.equals(b));
    }
}


Output:

false comparing with true = false


Last Updated : 09 Oct, 2018
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads