Java BitSet size() method

The size() method of Java BitSet class returns the total number of bit space actually in use by this BitSet to represent bit values. The maximum element in the set is the size - 1st element.

The default size of the bit set is 64-bit space. If the bit is set at index larger than the current BitSet size, it increases its bit space in the multiplication of 64*n, where n starts from 1, 2, 3, so on.

Syntax:

Parameter:

NA

Returns:

This method returns the number of bits space currently in this bit set.

Exception:

NA

Compatibility Version:

Java 1.0 and above

Example 1

Output:

bitset1: {1, 2, 4, 63}
bitset2: {10, 20, 30, 40, 64}
size of bitset1: 64
size of bitset2: 128