Clears all bits in this bit set that are set in other. The resulting value of a bit
in this bit set is true only if it was originally true and the corresponding
bit in other is false.
public voidor(BitSet other)
Logically ORs this bit set with other and changes the value of this set to the
result. The resulting value of a bit in this bit set is TRue only if it was
originally true or the corresponding bit in other is TRue.
public voidxor(BitSet other)
Logically XORs this bit set with other and changes the value of this set to
the result. The resulting value of a bit in this bit set is true only if it has a
value different from the corresponding bit in other.
You can also ask whether the current bit set has any true bits in common with a second bit set by using the
intersects method.
The remaining methods are
public intcardinality()
Returns the number of bits in this bit set that are true.
public intsize()
Returns the number of bits actually stored in this BitSet. Setting a bit index
greater than or equal to this value may increase the storage used by the set.
public intlength()
Returns the index of the highest set bit in this BitSet plus one.
public booleanisEmpty()
Returns true if this bit set has no TRue bits.
public inthashCode()
Returns a hash code for this set based on the values of its bits. Do not change
values of bits while a BitSet is in a hash map, or the set will be misplaced.
public booleanequals(Object other)
Returns true if all the bits in other are the same as those in this set.
Here is a class that uses a BitSet to mark which characters occur in a string. Each position in the bit set
represents the numerical value of a character: The 0th position represents the null character (\u0000), the
97 th bit represents the character a, and so on. The bit set can be printed to show the characters that it found:
public class WhichChars {
private BitSet used = new BitSet();
public WhichChars(String str) {
for (int i = 0; i < str.length(); i++)