Packages This Package Prev Next Index
§3.1 Class BitSet
public final class java.util.BitSet
extends java.lang.Object (I-§1.12)
implements java.lang.Cloneable (I-§1.22)
{
// Constructors
public BitSet(); §3.1.1
public BitSet(int nbits); §3.1.2
// Methods
public void and(BitSet set); §3.1.3
public void clear(int bit); §3.1.4
public Object clone(); §3.1.5
public boolean equals(Object obj); §3.1.6
public boolean get(int bit); §3.1.7
public int hashCode(); §3.1.8
public void or(BitSet set); §3.1.9
public void set(int bit); §3.1.10
public int size(); §3.1.11
public String toString(); §3.1.12
public void xor(BitSet set); §3.1.13
}
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 inded by nonnegative integers. Individual 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.
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.
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
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
clone
public Object clone()
- 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 (I-§3.1.11).
- Returns:
- a clone of this bit set.
- Overrides:
- clone in class Object (I-§1.12.2).
equals
public boolean equals(Object obj)
- 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 (I-§3.1.11) 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 (I-§1.12.3).
get
public boolean get(int bit)
- Parameters:
bit
-
the bit index
- Returns:
- the value of the bit with the specified index.
hashCode
public int hashCode()
- Returns:
- a hash code value for this bit set.
- Overrides:
- hashCode in class Object (I-§1.12.6).
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
set
public void set(int bit)
- Sets the bit specified by the index to true.
- Parameters:
bit
-
a bit index.
size
public int size()
- Returns:
- the number of bits currently in this bit set.
toString
public String toString()
- Returns:
- a string representation of this bit set.
- Overrides:
- toString in class Object (I-§1.12.9).
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
Packages This Package Prev Next Index
Java API Document (HTML generated by dkramer on April 22, 1996)
Copyright © 1996 Sun Microsystems, Inc.
All rights reserved
Please send any comments or corrections to doug.kramer@sun.com