Java编程 统计字符串A中有多少个类型为(字符串B)的子串 我们考试用最好明后天出答案
来源:百度知道 编辑:UC知道 时间:2024/06/07 08:40:36
public static void main(String[] args) throws Exception {
String a = "abcedfgbcdefgbcdefg";
String b = "bcd";
Matcher m = Pattern.compile(Pattern.quote(b)).matcher(a);
int i = 0;
while (m.find()) {
i++;
}
System.out.println(i);
}
Matcher和Pattern需要java.utils.regex.*
调试通过。