Java BitSet equals() method

The equals() method of Java BitSet class is used to compare the current BitSet object with specified object. The result of comparing BitSet bit with BitSet object returns true if and only if the specified object is not null and the set of BitSet object must have exactly same set of bit set to true as this BitSet.

For every non-negative int index i, the followinh condition:

Syntax:

Parameter:

DataTypeParameterDescription
ObjectobjIt is an object which is to be compared with this BitSet sets.

Returns:

This method returns true if the objects are the same as current bit set otherwise, returns false.

Exception:

NA

Compatibility Version:

Java 1.0 and above

Example 1

Output:

bitset:{0, 1, 2, 3, 4}
object:{0, 1, 2, 3, 4}
BitSet is equal to specified Object

Example 2

The equals() method return false, if the length of sets of BitSet are not equal to the length of BitSet object or even all the index of BitSet are not equals to the index of BitSet object.

Output:

bitset1:{0, 1, 2, 3, 4, 5}
bitset2:{0, 1, 2, 3, 5}
object:{0, 1, 2, 3, 4}
BitSet1 is not equal to specified Object
BitSet2 is not equal to specified Object