BitSet bitSet = new BitSet(8); // create a BitSet with 8 bits bitSet.set(0, 8); // set all bits to true System.out.println("Initial BitSet: " + bitSet.toString()); // prints Initial BitSet: {0, 1, 2, 3, 4, 5, 6, 7} bitSet.clear(); // clear all bits System.out.println("Cleared BitSet: " + bitSet.toString()); // prints Cleared BitSet: {}
BitSet bitSet = new BitSet(8); // create a BitSet with 8 bits bitSet.set(3); // set bit at index 3 to true System.out.println("Initial BitSet: " + bitSet.toString()); // prints Initial BitSet: {3} bitSet.clear(3); // clear bit at index 3 System.out.println("Cleared BitSet: " + bitSet.toString()); // prints Cleared BitSet: {}This method is part of the Java standard library, specifically the java.util package.