BitSet
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.
Every bit set has a current size, which is the number of bits of space currently in use by the bit set. Note that the size is related to the implementation of a bit set, so it may change with implementation. The length of a bit set relates to logical length of a bit set and is defined independently of implementation.
Unless otherwise noted, passing a null parameter to any of the methods in a BitSet will result in a NullPointerException.
A BitSet is not safe for multithreaded use without external synchronization.
Author
Arthur van Hoff
Michael McCloskey
Martin Buchholz
Since
1.0
Constructors
Functions
Returns the number of bits set to true in this BitSet.
Returns the value of the bit with the specified index. The value is true if the bit with the index bitIndex is currently set in this BitSet; otherwise, the result is false.
Returns a new BitSet composed of bits from this BitSet from fromIndex (inclusive) to toIndex (exclusive).
Returns true if the specified BitSet has any bits set to true that are also set to true in this BitSet.
Returns the index of the first bit that is set to false that occurs on or after the specified starting index.
Returns the index of the first bit that is set to true that occurs on or after the specified starting index. If no such bit exists then -1 is returned.
Returns the index of the nearest bit that is set to false that occurs on or before the specified starting index. If no such bit exists, or if -1 is given as the starting index, then -1 is returned.
Returns the index of the nearest bit that is set to true that occurs on or before the specified starting index. If no such bit exists, or if -1 is given as the starting index, then -1 is returned.
Sets the bit at the specified index to true.
Sets the bit at the specified index to the specified value.
Sets the bits from the specified fromIndex (inclusive) to the specified toIndex (exclusive) to true.
Sets the bits from the specified fromIndex (inclusive) to the specified toIndex (exclusive) to the specified value.
Returns a new byte array containing all the bits in this bit set.
Returns a new long array containing all the bits in this bit set.
Returns a string representation of this bit set. For every index for which this BitSet contains a bit in the set state, the decimal representation of that index is included in the result. Such indices are listed in order from lowest to highest, separated by ", " (a comma and a space) and surrounded by braces, resulting in the usual mathematical notation for a set of integers.
Attempts to reduce internal storage used for the bits in this bit set. Calling this method may, but is not required to, affect the value returned by a subsequent call to the .size method.