Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
Boolean compare() method in Java with Examples
Next article icon

Boolean equals() method in Java with examples

Last Updated : 09 Oct, 2018
Comments
Improve
Suggest changes
Like Article
Like
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  


Next Article
Boolean compare() method in Java with Examples

K

kundankumarjha
Improve
Article Tags :
  • Java
  • Java - util package
  • Java-Boolean
  • Java-Functions
Practice Tags :
  • Java

Similar Reads

  • Byte equals() method in Java with examples
    The equals() method of Byte class is a built in method in Java which is used to compare the equality given Object with the instance of Byte invoking the equals() method. Syntax ByteObject.equals(Object a) Parameters: It takes an Object type object a as input which is to be compared with the instance
    2 min read
  • Double.equals() Method in Java with Examples
    The java.lang.Double.equals() is a built-in function in java that compares this object to the specified object. The result is true if and only if the argument is not null and is a Double object that contains the same double value as this object. It returns false if both the objects are not same. In
    2 min read
  • BitSet equals() Method in Java with Examples
    The equals() method of Java BitSet class is used to check for equality between two bitsets. It verifies whether the elements of one set passed as a parameter is equal to the elements of this set or not. The method returns true if the bitsets match else false. Syntax: Bit_Set1.equals(Bit_Set2) Parame
    2 min read
  • Date equals() method in Java with Examples
    The equals() method of Java Date class checks if two Dates are equal, based on millisecond difference. Syntax: public boolean equals(Object obj) Parameters: The function accepts a single parameter obj which specifies the object to be compared with. Return Value: The function gives 2 return values sp
    2 min read
  • Boolean compare() method in Java with Examples
    The compare() method of Boolean class is a built in method in Java which is used to compare two boolean values. It is a static method, so it can be called without creating any object of the Boolean class i.e. directly using the class name. Syntax: Boolean.compare(boolean a, boolean b) Parameters: It
    2 min read
  • CompositeName equals() method in Java with Examples
    The equals() method of a javax.naming.CompositeName class is used to compare this CompositeName with the specified object passed as a parameter and checks whether two objects are equal or not. If both objects are equal then the equals() method returns true else false. If passed obj is null or not a
    2 min read
  • Java File Class equals() Method with Examples
    The equals() method of Java File Class compares the pathname supplied in the argument to the pathname provided in the argument. If the parameter is not null and points to the same file or directory, this function returns true. The operating system determines if the two abstract pathnames are equival
    2 min read
  • CompoundName equals() method in Java with Examples
    The equals() method of a javax.naming.CompoundName class is used to compare this CompoundName with the specified object passed as a parameter and checks whether two objects are equal or not. If both objects are equal then the equals() method returns true else false. If passed obj is null or not a co
    2 min read
  • Charset equals() method in Java with Examples
    The equals() method is a built-in method of the java.nio.charset checks if a given object of charset is equal to another given object of the charset. Two charsets are considered equal if, and only if, they have the same canonical names. A charset is never equal to any other type of object. Syntax: p
    2 min read
  • ChoiceFormat equals() method in Java with Examples
    The equals() method of java.text.ChoiceFormat class is used to compare between two ChoiceFormat objects and give the Boolean value regarding the comparison.Syntax: public boolean equals(Object obj) Parameter: This method takes obj as parameter which is another ChoiceFormat object for comparison.Retu
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences