question: 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 ; }
target:  Usage: for(int i=bs.nextSetBit(0); i&gt;=0; i=bs.nextSetBit(i+1)) { operate on index i here }