img
Method
Description
int nextSetBit(int star tIndex)
Returns the index of the next set bit (that is, the next 1 bit),
star ting from the index specified by star tIndex. If no bit is set,
­1 is returned.
void or(BitSet bitSet)
ORs the contents of the invoking BitSet object with that
specified by bitSet. The result is placed into the invoking object.
void set(int index)
Sets the bit specified by index.
void set(int index, boolean v)
Sets the bit specified by index to the value passed in v. true
sets the bit, false clears the bit.
void set(int star tIndex,
Sets the bits from star tIndex to endIndex­1.
int endIndex)
void set(int star tIndex,
Sets the bits from star tIndex to endIndex­1, to the value
int endIndex, boolean v) passed in v. true sets the bits, false clears the bits.
int size( )
Returns the number of bits in the invoking BitSet object.
String toString( )
Returns the string equivalent of the invoking BitSet object.
void xor(BitSet bitSet)
XORs the contents of the invoking BitSet object with that
specified by bitSet. The result is placed into the invoking object.
TABLE 18-2
The Methods Defined by BitSet (continued)
Here is an example that demonstrates BitSet:
// BitSet Demonstration.
import java.util.BitSet;
class BitSetDemo {
public static void main(String args[]) {
BitSet bits1 = new BitSet(16);
BitSet bits2 = new BitSet(16);
// set some bits
for(int i=0; i<16; i++) {
if((i%2) == 0) bits1.set(i);
if((i%5) != 0) bits2.set(i);
}
System.out.println("Initial pattern in bits1: ");
System.out.println(bits1);
System.out.println("\nInitial pattern in bits2: ");
System.out.println(bits2);
// AND bits
bits2.and(bits1);
System.out.println("\nbits2 AND bits1: ");
System.out.println(bits2);
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home