Re: Problem with BitSet.length()...



Mothra wrote:
Running eightBits.length() returns zero, rather than eight.

Logically speaking, if length() returns the perceived size and not the actual size, then there would be a function that returns the actual size if it might be pertinent. This function would also have a name similar to "length", like "capacity" or "size". Capacity is used for both ArrayList and String{Builder,Buffer}, for example. Searching the Javadocs for BitSet reveals this (in the function summary table):

size() - Returns the number of bits of space actually in use by this BitSet to represent bit values.

private static int bitsToInt(BitSet bits) {

What if BitSet.size() > 32?


--
Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth
.