作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
BitSet 类中的该方法用于返回第一个设置为 false 的位的索引
import java.util.BitSet;
public class BitSetDemo {
public static void main(String[] args) {
BitSet b = new BitSet();
b.set(5);
b.set(9);
b.set(6);
System.out.println(""+b);
System.out.println(b.nextClearBit(5));
System.out.println(b.nextClearBit(9));
}
}
Output :
{5, 6, 9}
7
10
在此代码中,6 在 9 之后设置,但它表明这些值是连续存储的((b.nextClearBit(5) 返回下一个值,即 7)。那么,BitSet 如何存储这些值?
最佳答案
nextClearBit
的 javadoc说:
Returns the index of the first bit that is set to
false
that occurs on or after the specified starting index.
您已将 5、6 和 9 设置为 true。也就是说,从5开始,第一个设置为false的索引是7。而从9开始,第一个设置为false的索引是10。根据你自己的输出,这也是返回的内容。
如果你想知道如何BitSet
工作原理以及它的作用,请阅读其 Javadoc 并查看源代码。它包含在 JDK 中。
关于java - java中BitSet的nextClearBit()实际上是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53694377/
有人可以解释一下我尝试从 javadoc 中理解的实际 bitSet.nextClearBit 是什么,但我无法清楚地了解它如何设置为 false。 最佳答案 在 boolean 逻辑中,术语set和
我是一名优秀的程序员,十分优秀!