Java BitSet length() method

The length() method of Java BitSet class returns the "logical size" of this BitSet. The length of BitSet goes up to the index of the highest set bit plus one. It returns zero if the BitSet does not contain any set bit.

Syntax:

Parameter:

NA

Returns:

The length() method returns the logical size of this BitSet.

Exception:

NA

Compatibility Version:

Java 1.2 and above

Example 1

Output:

bitset1: {}
bitset2: {1, 2, 3, 4}
bitset3: {2, 4, 6, 8, 10, 12}
length of bitset1: 0
length of bitset2: 5
length of bitset3: 13