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 equals() method in Java with examples
Next article icon

BitSet equals() Method in Java with Examples

Last Updated : 27 Dec, 2018
Comments
Improve
Suggest changes
Like Article
Like
Report
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)
Parameters: The method accepts one parameter Bit_Set2 of bitset type and refers to the set whose equality is to be checked with this bit set. Return Value: The method returns true if the equality holds for both the object set else it returns false. Below programs illustrate the working of BitSet equals() method in Java. Program 1: Java
// Java code to illustrate equals() import java.util.*;  public class BitSet_Demo {     public static void main(String args[])     {         // Creating an empty BitSet         BitSet bit_set1 = new BitSet();         BitSet bit_set2 = new BitSet();          // Use set() method to add elements into the Set         bit_set1.set(40);         bit_set1.set(25);         bit_set1.set(80);         bit_set1.set(95);         bit_set1.set(5);          // Use set() method to add elements into the Set         bit_set2.set(25);         bit_set2.set(40);         bit_set2.set(5);         bit_set2.set(95);         bit_set2.set(80);          // Displaying the BitSets         System.out.println("First BitSet: " + bit_set1);         System.out.println("Second BitSet: " + bit_set2);          // Checking for equality         System.out.println("Are the sets equal? "                            + bit_set1.equals(bit_set2));     } } 
Output:
  First BitSet: {5, 25, 40, 80, 95}  Second BitSet: {5, 25, 40, 80, 95}  Are the sets equal? true  
Program 2: Java
// Java code to illustrate equals() import java.util.*;  public class BitSet_Demo {     public static void main(String args[])     {         // Creating an empty BitSet         BitSet bit_set1 = new BitSet();         BitSet bit_set2 = new BitSet();          // Use set() method to add elements into the Set         bit_set1.set(40);         bit_set1.set(25);         bit_set1.set(80);         bit_set1.set(95);         bit_set1.set(5);          // Use set() method to add elements into the Set         bit_set2.set(10);         bit_set2.set(20);         bit_set2.set(30);         bit_set2.set(40);         bit_set2.set(50);          // Displaying the BitSets         System.out.println("First BitSet: " + bit_set1);         System.out.println("Second BitSet: " + bit_set2);          // Checking for equality         System.out.println("Are the sets equal? "                            + bit_set1.equals(bit_set2));     } } 
Output:
  First BitSet: {5, 25, 40, 80, 95}  Second BitSet: {10, 20, 30, 40, 50}  Are the sets equal? false  

Next Article
Boolean equals() method in Java with examples
author
chinmoy lenka
Improve
Article Tags :
  • Misc
  • Java
  • Java - util package
  • Java-Functions
  • Java-BitSet
Practice Tags :
  • Java
  • Misc

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
  • 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
  • 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
  • Double.equals() Method in Java with Examples
    The Double.equals() in Java is a built-in function from the java.lang.Double class. This method compares the content of two Double objects. 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. This method is useful for
    3 min read
  • Boolean equals() method in Java with examples
    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 re
    2 min read
  • ByteBuffer equals() method in Java with Examples
    The equals() method of java.nio.ByteBuffer class is used to check whether or not the given buffer is equal to another object. Two byte buffers are equal if, and only if, They have the same element type, They have the same number of remaining elements, and The two sequences of remaining elements, con
    3 min read
  • AbstractList equals() method in Java with Examples
    The equals() method of java.util.AbstractList class is used to compare the specified object with this list for equality. Returns true if and only if the specified object is also a list, both lists have the same size, and all corresponding pairs of elements in the two lists are equal. (Two elements e
    3 min read
  • DateFormat equals() Method in Java with Examples
    The equals() Method of the DateFormat class is used to compare two DateFormat objects. The method returns True if this DateFormat is equal to the passed object else returns False. Syntax: public boolean equals(Object obj) Parameters: The method takes one parameter obj of Object type and refers to th
    2 min read
  • AbstractMap equals() Method in Java with Examples
    The equals() method of the Java AbstractMap class is used to check equality between two maps. It compares the key-value pair in the current map with the key-value pair of the specified map. Syntax of AbstarctMap equals() Methodpublic boolean equals(Object o) Parameter: The Object to be compared with
    2 min read
  • Character.equals() method in Java with examples
    The java.lang.Character.equals() is a function in Java which compares this object against the specified object. If the argument is not null then the result is true and is a Character object that represents the same char value as this object. Syntax: public boolean equals(Object obj) Parameters: The
    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