java.lang.Object | |
↳ | java.util.BitSet |
The BitSet
class implements a
bit array.
Each element is either true or false. A BitSet
is created with a given size and grows
automatically if this size is exceeded.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates a new
BitSet with size equal to 64 bits. | |||||||||||
Creates a new
BitSet with size equal to bitCount , rounded up to
a multiple of 64. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Logically ands the bits of this
BitSet with bs . | |||||||||||
Clears all bits in this
BitSet which are also set in bs . | |||||||||||
Returns the number of bits that are
true in this BitSet . | |||||||||||
Clears the bit at index
index . | |||||||||||
Clears all the bits in this
BitSet . | |||||||||||
Clears the range of bits
[fromIndex, toIndex) . | |||||||||||
Creates and returns a copy of this
Object . | |||||||||||
Compares this instance with the specified object and indicates if they
are equal.
| |||||||||||
Flips the bit at index
index . | |||||||||||
Flips the range of bits
[fromIndex, toIndex) . | |||||||||||
Returns the bit at index
index . | |||||||||||
Returns a new
BitSet containing the
range of bits [fromIndex, toIndex) , shifted down so that the bit
at fromIndex is at bit 0 in the new BitSet . | |||||||||||
Returns an integer hash code for this object.
| |||||||||||
Returns true if
this.and(bs) is non-empty, but may be faster than computing that. | |||||||||||
Returns true if all the bits in this
BitSet are set to false, false otherwise. | |||||||||||
Returns the number of bits up to and including the highest bit set.
| |||||||||||
Returns the index of the first bit that is clear on or after
index . | |||||||||||
Returns the index of the first bit that is set on or after
index , or -1
if no higher bits are set. | |||||||||||
Logically ors the bits of this
BitSet with bs . | |||||||||||
Returns the index of the first bit that is clear on or before
index , or -1 if
no lower bits are clear or index == -1 . | |||||||||||
Returns the index of the first bit that is set on or before
index , or -1 if
no lower bits are set or index == -1 . | |||||||||||
Sets the bit at index
index to state . | |||||||||||
Sets the range of bits
[fromIndex, toIndex) to state . | |||||||||||
Sets the range of bits
[fromIndex, toIndex) . | |||||||||||
Sets the bit at index
index to true. | |||||||||||
Returns the capacity in bits of the array implementing this
BitSet . | |||||||||||
Returns a new
byte[] containing a little-endian representation the bits of
this BitSet , suitable for passing to valueOf to reconstruct
this BitSet . | |||||||||||
Returns a new
long[] containing a little-endian representation of the bits of
this BitSet , suitable for passing to valueOf to reconstruct
this BitSet . | |||||||||||
Returns a string containing a concise, human-readable description of the
receiver: a comma-delimited list of the indexes of all set bits.
| |||||||||||
Equivalent to
BitSet.valueOf(ByteBuffer.wrap(bytes)) . | |||||||||||
Returns a
BitSet corresponding to byteBuffer , interpreted as a little-endian
sequence of bits. | |||||||||||
Returns a
BitSet corresponding to longBuffer , interpreted as a little-endian
sequence of bits. | |||||||||||
Equivalent to
BitSet.valueOf(LongBuffer.wrap(longs)) , but likely to be faster. | |||||||||||
Logically xors the bits of this
BitSet with bs . |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Creates a new BitSet
with size equal to bitCount
, rounded up to
a multiple of 64.
NegativeArraySizeException | if bitCount < 0 .
|
---|
Clears all bits in this BitSet
which are also set in bs
.
Returns the number of bits that are true
in this BitSet
.
Clears the bit at index index
.
IndexOutOfBoundsException | if index < 0 .
|
---|
Clears all the bits in this BitSet
. This method does not change the capacity.
Use clear
if you want to reuse this BitSet
with the same capacity, but
create a new BitSet
if you're trying to potentially reclaim memory.
Clears the range of bits [fromIndex, toIndex)
.
IndexOutOfBoundsException | if fromIndex or toIndex is negative, or if
toIndex is smaller than fromIndex .
|
---|
Creates and returns a copy of this Object
. The default
implementation returns a so-called "shallow" copy: It creates a new
instance of the same class and then copies the field values (including
object references) from this instance to the new instance. A "deep" copy,
in contrast, would also recursively clone nested objects. A subclass that
needs to implement this kind of cloning should call super.clone()
to create the new instance and then create deep copies of the nested,
mutable objects.
Compares this instance with the specified object and indicates if they
are equal. In order to be equal, o
must represent the same object
as this instance using a class-specific comparison. The general contract
is that this comparison should be reflexive, symmetric, and transitive.
Also, no object reference other than null is equal to null.
The default implementation returns true
only if this ==
o
. See Writing a correct
equals
method
if you intend implementing your own equals
method.
The general contract for the equals
and hashCode()
methods is that if equals
returns true
for
any two objects, then hashCode()
must return the same value for
these objects. This means that subclasses of Object
usually
override either both methods or neither of them.
o | the object to compare this instance with. |
---|
true
if the specified object is equal to this Object
; false
otherwise.Flips the bit at index index
.
IndexOutOfBoundsException | if index < 0 .
|
---|
Flips the range of bits [fromIndex, toIndex)
.
IndexOutOfBoundsException | if fromIndex or toIndex is negative, or if
toIndex is smaller than fromIndex .
|
---|
Returns the bit at index index
. Indexes greater than the current length return false.
IndexOutOfBoundsException | if index < 0 .
|
---|
Returns a new BitSet
containing the
range of bits [fromIndex, toIndex)
, shifted down so that the bit
at fromIndex
is at bit 0 in the new BitSet
.
IndexOutOfBoundsException | if fromIndex or toIndex is negative, or if
toIndex is smaller than fromIndex .
|
---|
Returns an integer hash code for this object. By contract, any two
objects for which equals(Object)
returns true
must return
the same hash code value. This means that subclasses of Object
usually override both methods or neither method.
Note that hash values must not change over time unless information used in equals comparisons also changes.
See Writing a correct
hashCode
method
if you intend implementing your own hashCode
method.
Returns true if this.and(bs)
is non-empty, but may be faster than computing that.
Returns true if all the bits in this BitSet
are set to false, false otherwise.
Returns the number of bits up to and including the highest bit set. This is unrelated to
the size()
of the BitSet
.
Returns the index of the first bit that is clear on or after index
.
Since all bits past the end are implicitly clear, this never returns -1.
IndexOutOfBoundsException | if index < 0 .
|
---|
Returns the index of the first bit that is set on or after index
, or -1
if no higher bits are set.
IndexOutOfBoundsException | if index < 0 .
|
---|
Returns the index of the first bit that is clear on or before index
, or -1 if
no lower bits are clear or index == -1
.
IndexOutOfBoundsException | if index < -1 . |
---|
Returns the index of the first bit that is set on or before index
, or -1 if
no lower bits are set or index == -1
.
IndexOutOfBoundsException | if index < -1 . |
---|
Sets the bit at index index
to state
.
IndexOutOfBoundsException | if index < 0 .
|
---|
Sets the range of bits [fromIndex, toIndex)
to state
.
IndexOutOfBoundsException | if fromIndex or toIndex is negative, or if
toIndex is smaller than fromIndex .
|
---|
Sets the range of bits [fromIndex, toIndex)
.
IndexOutOfBoundsException | if fromIndex or toIndex is negative, or if
toIndex is smaller than fromIndex .
|
---|
Sets the bit at index index
to true.
IndexOutOfBoundsException | if index < 0 .
|
---|
Returns the capacity in bits of the array implementing this BitSet
. This is
unrelated to the length of the BitSet
, and not generally useful.
Use nextSetBit(int)
to iterate, or length()
to find the highest set bit.
Returns a new byte[]
containing a little-endian representation the bits of
this BitSet
, suitable for passing to valueOf
to reconstruct
this BitSet
.
Returns a new long[]
containing a little-endian representation of the bits of
this BitSet
, suitable for passing to valueOf
to reconstruct
this BitSet
.
Returns a string containing a concise, human-readable description of the
receiver: a comma-delimited list of the indexes of all set bits.
For example: "{0,1,8
"}.
Equivalent to BitSet.valueOf(ByteBuffer.wrap(bytes))
.
Returns a BitSet
corresponding to byteBuffer
, interpreted as a little-endian
sequence of bits. This method does not alter the ByteBuffer
.
Returns a BitSet
corresponding to longBuffer
, interpreted as a little-endian
sequence of bits. This method does not alter the LongBuffer
.
Equivalent to BitSet.valueOf(LongBuffer.wrap(longs))
, but likely to be faster.
This is likely to be the fastest way to create a BitSet
because it's closest
to the internal representation.