BitSet bitSet = new BitSet();
bitSet.set(5);
bitSet.clear(5);
if (bitSet.get(5)) { // do something }
BitSet bitSet1 = new BitSet(); BitSet bitSet2 = new BitSet(); bitSet1.set(0); bitSet2.set(2); bitSet1.or(bitSet2);In this example, the resulting BitSet will have bits set at indexes 0 and 2. Overall, the java.util BitSet class provides a useful way to work with sets of bits in Java.