Java BitSet - equals() Method
The java.util.BitSet.equals() method is used to compare the given BitSet against the specified object. It returns true if the argument is not null and is the specified BitSet object that has exactly the same set of bits set to true as this BitSet.
Syntax
public boolean equals(Object obj)
Parameters
obj |
Specify the object to compare with. |
Return Value
Returns true if the objects are the same, else returns false.
Exception
NA
Example:
In the example below, the java.util.BitSet.equals() method is used to compare the given BitSet against the specified object.
import java.util.*; public class MyClass { public static void main(String[] args) { //creating BitSets BitSet BSet1 = new BitSet(); BitSet BSet2 = new BitSet(); BitSet BSet3 = new BitSet(); //populating BSet1 BSet1.set(10); BSet1.set(20); BSet1.set(30); //populating BSet2 BSet2.set(10); BSet2.set(20); BSet2.set(30); //populating BSet3 BSet3.set(11); BSet3.set(22); BSet3.set(33); //comparing BSet1 and BSet2 System.out.println("Is BSet1 equal to BSet2: " + BSet1.equals(BSet2)); //comparing BSet1 and BSet3 System.out.println("Is BSet1 equal to BSet3: " + BSet1.equals(BSet3)); } }
The output of the above code will be:
Is BSet1 equal to BSet2: true Is BSet1 equal to BSet3: false
❮ Java.util - BitSet