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 Comment More infoAdvertise with us Next Article BitSet equals() Method in Java with Examples chinmoy lenka Follow Improve Article Tags : Misc Java Java - util package Java-Functions Java-BitSet +1 More Practice Tags : JavaMisc 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 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 t 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 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 Like