Java BitSet stream() 方法

7 Jan 2025 | 1 分钟阅读

Java BitSet 类的 stream() 方法返回一个流,其中包含当前 BitSet 中设置为 true 的位的索引。返回的索引是 BitSet 中设置为 true 值的位置,并且按递增顺序排列。流的大小指的是设置为 true 的位的总数,这等于 cardinality() 方法返回的值。

语法

参数

不适用

返回值

stream() 方法返回一个流,其中包含当前 BitSet 中设置为 true 的位的索引。

Exception

不适用

兼容版本

Java 1.8 及以上版本

示例 1

输出

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