nextClearBit()
is an instance method of the BitSet
which is used to get the index of the first bit that is set to false
on or after the given beginning index.
The nextClearBit()
method is defined in the BitSet
class. The BitSet
class is defined in the java.util
package. To import the BitSet
class, check the following import statement.
import java.util.BitSet;
The syntax of nextClearBit()
is as follows:
public int nextClearBit(int fromIndex)
int fromIndex
: The starting index.This method returns the index of the next clear bit.
Let’s look at a working example of the nextClearBit()
method:
import java.util.BitSet; public class Main{ public static void main(String[] args) { // Create empty BitSet object BitSet bitSet = new BitSet(); // Set the bit at index 2 bitSet.set(2); // Set the bit at index 8 bitSet.set(8); int startingIndex = 4; // get the first bit set to false from the startingIndex System.out.printf("%s.nextClearBit(%s) = %s", bitSet, startingIndex, bitSet.nextClearBit(startingIndex)); } }
BitSet
class.BitSet
class.BitSet
object.nextClearBit
method.false
from the startingIndex
using the nextClearBit
method.RELATED TAGS
CONTRIBUTOR
View all Courses