Skip to content

Tag: bitset

How to flip all the bits in Java BitSet while preserving its length

How can I flip all the bits in a Java BitSet, while preserving its length? For example, given the following BitSet: Is there a simple method to flip all the bits, while preserving the BitSet length (6, in the above example)? I would like to get: Answer BitSet has a flip(from, to) method, which allows you to flip bits in