I would like to store numbers, from 1 to N, sequentially in an array of BitSet. Is there an alternate solution apart from using the set() method on each number? Thanks!
1 Answer
There are operations for setting a range of bits in a BitSet; e.g. set(from, to, value). So for example,
for (int i = from; i < to; i++) {
bitset.set(i, true);
}
is equivalent to
bitset.set(from, to, true);
The latter form is most likely a lot faster.