Package java.util Previous
Previous
Java API
Java API
Index
Index
Next
Next

Class BitSet

Constructors , Methods

public  final  class  java.util.BitSet
    extends  java.lang.Object  
    implements java.lang.Cloneable  
{
        // Constructors
    public BitSet();	
    public BitSet(int  nbits);	

        // Methods
    public void and(BitSet  set);	
    public void clear(int  bit);	
    public Object clone();	
    public boolean equals(Object  obj);	
    public boolean get(int  bit);	
    public int hashCode();	
    public void or(BitSet  set);	
    public void set(int  bit);	
    public int size();	
    public String toString();	
    public void xor(BitSet  set);	
}

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.


Constructors


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.

ParameterDescription
nbits the initial size of the bit set.


Methods


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.

ParameterDescription
set a bit set


clear

public void clear(int  bit) 

Sets the bit specified by the index to false.

ParameterDescription
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 .

Return Value:

Returns a clone of this bit set.

Overrides:

clone in class Object .


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 of the two bit sets are not compared.

Return Value:

Returns true if the objects are the same; false otherwise.

ParameterDescription
obj the object to compare with

Overrides:

equals in class Object .


get

public boolean get(int  bit) 

Return Value:

Returns the value of the bit with the specified index.

ParameterDescription
bit the bit index


hashCode

public int hashCode() 

Return Value:

Returns a hash code value for this bit set.

Overrides:

hashCode in class Object .


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.

ParameterDescription
set a bit set


set

public void set(int  bit) 

Sets the bit specified by the index to true.

ParameterDescription
bit a bit index.


size

public int size() 

Return Value:

Returns the number of bits currently in this bit set.


toString

public String toString() 

Return Value:

Returns a string representation of this bit set.

Overrides:

toString in class Object .


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:

ParameterDescription
set a bit set



Top© 1996 Sun Microsystems, Inc. All rights reserved.