Java Reference
In-Depth Information
Returns the index of the highest set bit in this BitSet plus one.
public boolean isEmpty()
Returns true if this bit set has no TRue bits.
public int hashCode()
Returns a hash code for this set based on the values of its
bits. Do not change values of bits while a BitSet is in a hash
map, or the set will be misplaced.
public boolean equals(Object other)
Returns true if all the bits in other are the same as those in
this set.
Here is a class that uses a BitSet to mark which characters occur in a
string. Each position in the bit set represents the numerical value of a
character: The 0 th position represents the null character ( \u0000 ), the
97 th bit represents the character a , and so on. The bit set can be printed
to show the characters that it found:
public class WhichChars {
private BitSet used = new BitSet();
public WhichChars(String str) {
for (int i = 0; i < str.length(); i++)
used.set(str.charAt(i)); // set bit for char
}
public String toString() {
String desc = "[";
for (int i = used.nextSetBit(0);
i >= 0;
i = used.nextSetBit(i+1) ) {
desc += (char) i;
 
Search WWH ::




Custom Search