• Java Data Structures Tutorial

Adding values to the Bitset



BitSet class provides the set() method it is used to set the value of the specified bit to true. Set the required values of the created BitSet using the set() method.

Example

import java.util.BitSet;
public class CreatingBitSet {
   public static void main(String args[]) {
      
      BitSet bitSet = new BitSet(5);   
      bitSet.set(0);
      bitSet.set(2);
      bitSet.set(4);
      System.out.println(bitSet);      
   }
}

Output

{0, 2, 4}
Advertisements