[英]Encode an array of long values as a BitSet
I saw that we can encode an array of ints into a BitSet and retrieve them as in:我看到我们可以将一个整数数组编码到一个 BitSet 中并检索它们,如下所示:
int[] ints = new int[]{5, 7, 25, 100102244};
BitSet b = new BitSet();
for (int i=0;i<ints.length;i++)
b.set(ints[i]);
b.stream().forEach(i -> System.out.println(i));
which outputs哪个输出
5
7
25
100102244
Is it possible to do the same for an array of longs?是否可以对长数组做同样的事情?
Thanks in advance,提前致谢,
Use LongBuffer :使用LongBuffer :
import java.nio.*;
import java.util.*;
var buffer = LongBuffer.wrap(new long[] { 5, 7, 25, 100102244 });
var bitset = BitSet.valueOf(buffer);
System.out.println(bitset);
for (long l : bitset.toLongArray()) {
System.out.println(l);
}
{0, 2, 64, 65, 66, 128, 131, 132, 194, 197, 198, 204, 205, 206, 208, 209, 210, 212, 213, 214, 215, 216, 218}
5
7
25
100102244
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.