BitSetUtils { public static String toString(BitSet bits, int n) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { sb.append(bits.get(i) ? "1 " : "0 "); } return sb.toString(); } private  BitSetUtils(); static BitSet copy(BitSet b); static BitSet getRandomBits(int n, Random random); static String toString(BitSet bits, int n); static String toString(BitSet bits); static boolean innerProduct(BitSet a, BitSet b); static BitSet fromList(List<Boolean> list); static BitSet fromArray(boolean[] array); static boolean[] toArray(BitSet bitset, int length); static List<Boolean> toList(BitSet bitset, int n);  }
@Test public void testToString() { BitSet bitSet = new BitSet(8); bitSet.set(0); bitSet.set(5); bitSet.set(7); Assert.assertEquals("1 0 0 0 0 1 0 1 ", BitSetUtils.toString(bitSet)); Assert.assertEquals("", BitSetUtils.toString(bitSet, 0)); Assert.assertEquals("1 0 0 ", BitSetUtils.toString(bitSet, 3)); Assert.assertEquals("", BitSetUtils.toString(bitSet, -1)); }