我不太明白size()
和length()
in的不同含义BitSet
。检查下面的代码:
public class Sandbox {
public static void main(String argv[])
{
BitSet bitSet1 = new BitSet(16);
bitSet1.set(0);
bitSet1.set(8);
bitSet1.set(15);
displayBitSet(bitSet1);
}
static void displayBitSet(BitSet bitSet)
{
for(int i=0;i<bitSet.size();i++)
{
boolean bit = bitSet.get(i);
System.out.print(bit?1:0);
}
System.out.println(" "+bitSet.size()+" "+bitSet.length());
}
}
输出是:
1000000010000001000000000000000000000000000000000000000000000000 64 16
我以为我会得到类似的东西
1000000010000001 16 16
这些尾随零来自哪里?谁可以给我解释一下这个?谢谢~~