Code example for BitSet

Methods: set, toString

0
import java.util.BitSet; 
 
public class BitSetTest extends junit.framework.TestCase {
    public void test_toString() throws Exception { 
        // From the RI javadoc. 
        BitSet bs = new BitSet();
        assertEquals("{}", bs.toString());
        bs.set(2);
        assertEquals("{2}", bs.toString());
        bs.set(4);
        bs.set(10);
        assertEquals("{2, 4, 10}", bs.toString());
    } 
 
    private static void assertBitSet(BitSet bs, long[] longs, String s) {
        for (int i = 0; i < 64 * longs.length; ++i) {
            assertEquals(bs.toString(), ((longs[i / 64] & (1L << (i % 64))) != 0), bs.get(i));
        } 
        int cardinality = 0;
        for (int i = 0; i < longs.length; ++i) {
            cardinality += Long.bitCount(longs[i]);