Java BitSet get previous set bit

Description

Java BitSet get previous set bit

import java.util.BitSet;

public class Main {

   public static void main(String[] args) {
      BitSet bitSet = new BitSet();
      long[] array = { 1, 21, 3 };
      bitSet = BitSet.valueOf(array);
      System.out.println(bitSet);

      long[] tmp = bitSet.toLongArray();
      for (long number : tmp) {
         System.out.println(number);
      }//from  w  ww.  ja v a  2 s  . c  o  m

      // There's more
      System.out.println(bitSet.previousSetBit(1));
      System.out.println(bitSet.previousClearBit(66));

   }
}



PreviousNext

Related