import java.util.Arrays;
import java.util.Collections;
public class test {
public static void main(String[] args) {
String temp = "0001111111010010101010001011101111010";
String target = "1";
int count = Collections.frequency(Arrays.asList(temp.split("")), target);
System.out.println(count);
}
}
执行结果如下: