This class implements a vector of bits that grows as needed. Each component of the bit set has a boolean value. The bits of a BitSet are indexed by nonnegative integers. Individual indexed bits can be examined, set, or cleared. One BitSet may be used to modify the contents of another BitSet through logical AND, logical inclusive OR, and logical exclusive OR operations.By default, all bits in the set initially have the value false.
Important API:-
- void and(BitSet set)
Performs a logical AND of this target bit set with the argument bit set. - int cardinality()
Returns the number of bits set to true in this BitSet. - void clear()
Sets all of the bits in this BitSet to false. - boolean equals(Object obj)
Compares this object against the specified object. - void flip(int bitIndex)
Sets the bit at the specified index to the complement of its current value. - boolean get(int bitIndex)
Returns the value of the bit with the specified index. - boolean isEmpty()
Returns true if this BitSet contains no bits that are set to true. - int length()
Returns the “logical size” of this BitSet: the index of the highest set bit in the BitSet plus one - void or(BitSet set)
Performs a logical OR of this bit set with the bit set argument. - void set(int bitIndex)
Sets the bit at the specified index to true. - int size()
Returns the number of bits of space actually in use by this BitSet to represent bit values. - void xor(BitSet set)
Performs a logical XOR of this bit set with the bit set argument.