基于Javadoc,应打印以下代码6
。但是,它3
没有明显的原因输出。
import java.util.*;
public class BitSetStrangeness{
public static void main(String[] args){
BitSet foo = new BitSet();
int[] arbitrary = new int[] {
0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,1,0,0,0,0,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1
};
for (int i = 0; i < arbitrary.length; i++)
if (arbitrary[i] == 1) foo.set(i);
else foo.clear(i);
System.out.println(foo.get(15,21).length());
}
}
谁能解释a)为什么我看到这种行为和b)我如何修改代码来修复它,以便提取的Bitset长度为6而不是3?