Q: 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 :
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,

A: Use 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

