Java BitSet stream() method

The stream() method of Java BitSet class returns a stream of indices for which the current BitSet contains a bit. The return indices of bit are set to true value in the bit set and follow an increasing order. The size of stream refers to the total number of bits are set to true and it is equal to the value returned by the cardinality() method.

Syntax:

Parameter:

NA

Returns:

The stream() method returns a stream of indices for which the current BitSet contains a bit.

Exception:

NA

Compatibility Version:

Java 1.8 and above

Example 1

Output:

bitset: {0, 1, 3, 5, 6}
stream of indices: [email protected]
size of stream1: 5
bitset1: {0, 1, 3, 5}
stream of indices1: [email protected]
size of stream2: 4