public int nextSetBit(final int i){
  int x=i / 64;
  if (x >= this.data.length)   return -1;
  long w=this.data[x];
  w>>>=(i % 64);
  if (w != 0) {
    return i + Long.numberOfTrailingZeros(w);
  }
  ++x;
  for (; x < this.data.length; ++x) {
    if (this.data[x] != 0) {
      return x * 64 + Long.numberOfTrailingZeros(this.data[x]);
    }
  }
  return -1;
}

public int nextSetBit ( final int i ) { int x = i / 64 ; if ( x >= this . data . length ) return - 1 ; long w = this . data [ x ] ; w >>>= ( i % 64 ) ; if ( w != 0 ) { return i + Long . numberOfTrailingZeros ( w ) ; } ++ x ; for ( ; x < this . data . length ; ++ x ) { if ( this . data [ x ] != 0 ) { return x * 64 + Long . numberOfTrailingZeros ( this . data [ x ] ) ; } } return - 1 ; }
usage : for ( int i = bs . nextsetbit ( 0 ) ; i & gt ; = 0 ; i = bs . nextsetbit ( i + 1 ) ) { operate on index i here }
