All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class java.util.BitSet

java.lang.Object
   |
   +----java.util.BitSet

public final class BitSet
extends Object
implements Cloneable, Serializable
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.

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 currently in the bit set.

A BitSet is not synchronized against simultaneous access by several threads. If one thread is accessing the BitSet while another thread is modifying it, mixed results may occur. The alternative is to clone the BitSet and operate on the clone. A client may do that itself if it wants, but the basic data type should be fast.


Constructor Index

 o BitSet()
Creates a new bit set.
 o BitSet(int)
Creates a bit set whose initial size is the specified number of bits.

Method Index

 o and(BitSet)
Performs a logical AND of this target bit set with the argument bit set.
 o clear(int)
Sets the bit specified by the index to false.
 o clone()
Clones this BitSet.
 o equals(Object)
Compares this object against the specified object.
 o get(int)
Returns the value of the bit with the specified index.
 o hashCode()
Returns a hash code value for this bit set.
 o or(BitSet)
Performs a logical OR of this bit set with the bit set argument.
 o set(int)
Sets the bit specified by the index to true.
 o size()
Returns the number of bits currently in this bit set.
 o toString()
Returns a string representation of this bit set.
 o xor(BitSet)
Performs a logical XOR of this bit set with the bit set argument.

Constructors

 o BitSet
 public BitSet()
Creates a new bit set. All bits are initially false.

 o BitSet
 public BitSet(int nbits)
Creates a bit set whose initial size is the specified number of bits. All bits are initially false.

Parameters:
nbits - the initial size of the bit set.
Throws: NegativeArraySizeException
if the specified initial size is negative.

Methods

 o set
 public void set(int bit)
Sets the bit specified by the index to true.

Parameters:
bit - a bit index.
Throws: IndexOutOfBoundsException
if the specified index is negative.
 o clear
 public void clear(int bit)
Sets the bit specified by the index to false.

Parameters:
bit - the index of the bit to be cleared.
Throws: IndexOutOfBoundsException
if the specified index is negative.
 o get
 public boolean get(int bit)
Returns the value of the bit with the specified index.

Parameters:
bit - the bit index.
Returns:
the value of the bit with the specified index.
Throws: IndexOutOfBoundsException
if the specified index is negative.
 o and
 public void and(BitSet set)
Performs a logical AND of this target bit set with the argument bit set. This bit set is modified so that each bit in it has the value true if and only if it both initially had the value true and the corresponding bit in the bit set argument also had the value true.

Parameters:
set - a bit set.
 o or
 public void or(BitSet set)
Performs a logical OR of this bit set with the bit set argument. This bit set is modified so that a bit in it has the value true if and only if it either already had the value true or the corresponding bit in the bit set argument has the value true.

Parameters:
set - a bit set.
 o xor
 public void xor(BitSet set)
Performs a logical XOR of this bit set with the bit set argument. This bit set is modified so that a bit in it has the value true if and only if one of the following statements holds:

Parameters:
set - a bit set.
 o hashCode
 public int hashCode()
Returns a hash code value for this bit set.

Returns:
a hash code value for this bit set.
Overrides:
hashCode in class Object
 o size
 public int size()
Returns the number of bits currently in this bit set. The maximum element in the set is the size - 1st element.

Returns:
the number of bits currently in this bit set.
 o equals
 public boolean equals(Object obj)
Compares this object against the specified object. The result is true if and only if the argument is not null and is a Bitset object that has exactly the same set of bits set to true as this bit set. The current sizes of the two bit sets are not compared.

Parameters:
obj - the object to compare with.
Returns:
true if the objects are the same; false otherwise.
Overrides:
equals in class Object
See Also:
size
 o clone
 public Object clone()
Clones this BitSet. The clone of the bit set is another bit set that has exactly the same bits set to true as this bit set and the same current size.

Returns:
a clone of this bit set.
Overrides:
clone in class Object
See Also:
size
 o toString
 public String toString()
Returns a string representation of this bit set.

Returns:
a string representation of this bit set.
Overrides:
toString in class Object

All Packages  Class Hierarchy  This Package  Previous  Next  Index