length(): This method is available in java.util.BitSet class of Java.
Syntax:
int java.util.BitSet.length()
This method returns the "logical size" of this BitSet: the index of the highest set bit in the BitSet plus one.
Note: Returns zero if the BitSet contains no set bits.
Parameters: NA
Returns: the logical size of this BitSet.
Exceptions: NA
Approach
Java
import java.util.BitSet;public class BitSetlength {public static void main(String[] args) {BitSet bitSet = new BitSet(40);bitSet.set(1);bitSet.set(5);bitSet.set(6);bitSet.set(10);System.out.println(bitSet.length());}}
Output:
11
No comments:
Post a Comment