Java: Count number of bits set in a java.util.BitSet

Rnet picture Rnet · Feb 3, 2011 · Viewed 7.8k times · Source

Any quick method to count the number of set bits in a BitSet other than the usual 'keep a counter' method?

Answer

pwc picture pwc · Feb 3, 2011

The cardinality() method returns the number of set bits.