public boolean getAndSet ( int index ) { int wordNum = index >> 6 ; // div 64 int bit = index & 0x3f ; // mod 64 long bitmask = 1L << bit ; boolean val = ( bits [ wordNum ] & bitmask ) != 0 ; bits [ wordNum ] |= bitmask ; return val ; }
Sets a bit and returns the previous value . The index should be less than the BitSet size .