Generating sequential numbers using BitSet

71 Views Asked by At

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

There are 1 best solutions below

0
On BEST 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.