Java Reference
In-Depth Information
22.2. BitSet
The BitSet class provides a way to create a bit vector that grows dynam-
ically. In effect, a bit set is a vector of TRue or false bits indexed from 0 to
Integer.MAX_VALUE, all of them initially false . These bits can be individually
set, cleared, or retrieved. BitSet uses only sufficient storage to hold the
highest index bit that has been setany bits beyond that are deemed to
be false .
Methods that take indices into the set throw IndexOutOfBoundsException if a
supplied index is negative or, where relevant, if the from index is greater
than the to index.
There are two constructors for BitSet :
public BitSet(int size)
Creates a new bit set with enough initial storage to explicitly
represent bits indexed from 0 to size-1 . All bits are initially
false .
public BitSet()
Creates a new bit set with a default amount of initial storage.
All bits are initially false .
There are four methods for dealing with individual bits.
public void set(int index)
Sets the bit specified by index to TRue.
public void clear(int index)
Sets the bit specified by index to false .
 
Search WWH ::




Custom Search