BitSetUtils { public static BitSet fromList(List<Boolean> list) { BitSet bitset = new BitSet(list.size()); for (int i = 0; i < list.size(); i++) { bitset.set(i, list.get(i)); } return bitset; } 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 testFromList() { Boolean[] array = new Boolean[] { true, false, true, false, false, false, true }; List<Boolean> list = Arrays.asList(array); BitSet bitSet = BitSetUtils.fromList(list); for (int i = 0; i < array.length; i++) { Assert.assertEquals(array[i], bitSet.get(i)); } List<Boolean> emptyList = new LinkedList<>(); BitSet emptyBitSet = BitSetUtils.fromList(emptyList); Assert.assertTrue(emptyBitSet.isEmpty()); }