// create a new BitSet with a size of 8 bits BitSet bits = new BitSet(8);
// set bits at positions 1 and 3 bits.set(1); bits.set(3); // clear bit at position 2 bits.clear(2);
// check if bit at position 0 is set if (bits.get(0)) { System.out.println("Bit at position 0 is set"); } // check if any bits are set if (bits.isEmpty()) { System.out.println("No bits are set"); }Package Library: The BitSet class is part of the java.util package, which is a built-in Java library that provides a collection of utility classes and interfaces for working with various data structures such as lists, maps, and sets.