Java BitSet - isEmpty() Method
The java.util.BitSet.isEmpty() method is used to check whether the BitSet is empty or not. It returns true if the BitSet contains no bits, else returns false.
Syntax
public boolean isEmpty()
Parameters
No parameter is required.
Return Value
Returns true if the BitSet is empty, else returns false.
Exception
NA
Example:
In the example below, the java.util.BitSet.isEmpty() method is used to check whether the given BitSet is empty or not.
import java.util.*; public class MyClass { public static void main(String[] args) { //creating a BitSet BitSet BSet = new BitSet(); //checking BitSet for empty System.out.println("Is BSet empty?: " + BSet.isEmpty()); //populating BitSet BSet.set(10); BSet.set(20); BSet.set(30); BSet.set(40); BSet.set(50); //checking BitSet for empty System.out.println("Is BSet empty?: " + BSet.isEmpty()); } }
The output of the above code will be:
Is BSet empty?: true Is BSet empty?: false
❮ Java.util - BitSet