Java Utililty Methods BitSet

List of utility methods to do BitSet

Description

The list of methods to do BitSet are organized into topic(s).

Method

BitSetreverseBitSet(BitSet bs)
Noddy method to reverse a BitSet.
final BitSet copy = new BitSet(8);
int counter = 0;
int size = bs.length();
for (int i = 0; i < size; ++i) {
    if (i % 8 == 0 && i != 0) {
        for (int j = 8; j >= 1; j--) {
            bs.clear(i - j);
            if (copy.get(j - 1)) {
...
IteratorsetBitIterator(final BitSet b)
set Bit Iterator
return new Iterator<Integer>() {
    int nextBit = b.nextSetBit(0);
    @Override
    public boolean hasNext() {
        return nextBit >= 0;
    @Override
    public Integer next() {
...
voidsetBits(BitSet bitSet, Iterable indexes)
Set all bits on a given positions.
for (Integer index : indexes) {
    bitSet.set(index);
voidsetBitSet(BitSet bitSet, int x1, int x2, int y, int width)
set Bit Set
int idx = width * y + x1;
int idx2 = width * y + x2;
for (; idx < idx2; idx++) {
    bitSet.set(idx);
voidshiftLeft(BitSet bs, int n)
shift Left
for (int i = bs.length() - 1; i >= 0; i = bs.previousSetBit(i - 1)) {
    bs.clear(i);
    bs.set(i + 1);
BitSetshiftLeft(BitSet s, int length)
Shifts bits of a BitSet object one place to the left.
for (int i = length; i > 0; i--) {
    s.set(i, s.get(i - 1));
s.set(0, false);
return s;
BitSetshiftLeft(BitSet src, int offset)
shift Left
if (offset < 0)
    return src;
BitSet result = new BitSet();
int i;
for (i = 0; i < src.length(); i++) {
    if (src.get(i)) {
        result.set(i + offset, true);
return result;
BitSetshiftRight(BitSet bitset, int n)
shift Right
return bitset.get(n, Math.max(n, bitset.length()));
voidstoreCharSet(BitSet stored, String... validCharStrings)
store Char Set
for (String validCharString : validCharStrings) {
    for (char c : validCharString.toCharArray()) {
        stored.set(c);
BitSetstrArrToBitSet(String stringArray)
Convert a String containing integers separated by space to an BitSet containing the integers as set members
BitSet bs = new BitSet();
StringTokenizer tk = new StringTokenizer(stringArray);
while (tk.hasMoreTokens()) {
    Integer theInt = null;
    try {
        theInt = new Integer(tk.nextToken());
    } catch (NumberFormatException e) {
        theInt = null;
...