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.
-
BitSet()
- Creates a new bit set.
-
BitSet(int)
- Creates a bit set whose initial size is the specified number of
bits.
-
and(BitSet)
- Performs a logical AND of this target bit set with the
argument bit set.
-
clear(int)
- Sets the bit specified by the index to
false
.
-
clone()
- Clones this BitSet.
-
equals(Object)
- Compares this object against the specified object.
-
get(int)
- Returns the value of the bit with the specified index.
-
hashCode()
- Returns a hash code value for this bit set.
-
or(BitSet)
- Performs a logical OR of this bit set with the bit set
argument.
-
set(int)
- Sets the bit specified by the index to
true
.
-
size()
- Returns the number of bits currently in this bit set.
-
toString()
- Returns a string representation of this bit set.
-
xor(BitSet)
- Performs a logical XOR of this bit set with the bit set
argument.
BitSet
public BitSet()
- Creates a new bit set. All bits are initially
false
.
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.
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.
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.
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.
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.
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.
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:
- The bit initially has the value
true
, and the
corresponding bit in the argument has the value false
.
- The bit initially has the value
false
, and the
corresponding bit in the argument has the value true
.
- Parameters:
- set - a bit set.
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
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.
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
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
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