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!
Asked
Active
Viewed 55 times
1 Answers
1
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.

Stephen C
- 698,415
- 94
- 811
- 1,216