size(): This method is available in java.util.BitSet class of Java.
Syntax:
int java.util.BitSet.size()
This method returns the number of bits of space actually in use by this BitSet to represent bit values.
Note: The maximum element in the set is the size - 1st element.
Parameters: NA
Returns: the number of bits currently in this bit set.
Exceptions: NA
Approach
Java
import java.util.BitSet;public class BitSetsize {public static void main(String[] args) {BitSet bitSet = new BitSet(100);bitSet.set(1);bitSet.set(50);bitSet.set(6);bitSet.set(10);System.out.println(bitSet.size());}}
Output:
128
No comments:
Post a Comment