img
BitSet
A BitSet class creates a special type of array that holds bit values. This array can increase in size
as needed. This makes it similar to a vector of bits. The BitSet constructors are shown here:
BitSet( )
BitSet(int size)
The first version creates a default object. The second version allows you to specify its initial
size (that is, the number of bits that it can hold). All bits are initialized to zero.
BitSet defines the methods listed in Table 18-2.
Method
Description
void and(BitSet bitSet)
ANDs the contents of the invoking BitSet object with those
specified by bitSet. The result is placed into the invoking
object.
void andNot(BitSet bitSet)
For each 1 bit in bitSet, the corresponding bit in the invoking
BitSet is cleared.
int cardinality( )
Returns the number of set bits in the invoking object.
void clear( )
Zeros all bits.
void clear(int index)
Zeros the bit specified by index.
void clear(int star tIndex,
Zeros the bits from star tIndex to endIndex­1.
int endIndex)
Object clone( )
Duplicates the invoking BitSet object.
boolean equals(Object bitSet)
Returns true if the invoking bit set is equivalent to the one
passed in bitSet. Other wise, the method returns false.
void flip(int index)
Reverses the bit specified by index.
void flip(int star tIndex,
Reverses the bits from star tIndex to endIndex­1.
int endIndex)
boolean get(int index)
Returns the current state of the bit at the specified index.
BitSet get(int star tIndex,
Returns a BitSet that consists of the bits from star tIndex
int endIndex)
to endIndex­1. The invoking object is not changed.
int hashCode( )
Returns the hash code for the invoking object.
boolean intersects(BitSet bitSet) Returns true if at least one pair of corresponding bits within
the invoking object and bitSet are 1.
boolean isEmpty( )
Returns true if all bits in the invoking object are zero.
int length( )
Returns the number of bits required to hold the contents of
the invoking BitSet. This value is determined by the location
of the last 1 bit.
int nextClearBit(int star tIndex)
Returns the index of the next cleared bit (that is, the next
zero bit), star ting from the index specified by star tIndex.
TABLE 18-2
The Methods Defined by BitSet
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home