Java examples for java.util:BitSet
String to BitSet
//package com.java2s; import java.util.BitSet; public class Main { public static void main(String[] argv) throws Exception { String s = "java2s.com"; int length = 2; System.out.println(toBitSet(s, length)); }//w ww. j a va 2 s . c o m public static BitSet toBitSet(String s, int length) { int len = s.length(); BitSet bs = new BitSet(length); for (int i = 0; i < len; i++) { if (s.charAt(i) == '1') bs.set(i); } return bs; } }