自己琢磨的一个解决办法,还有其他更快的吗?
class TestCount {
public static void main(String[] args) {
String str = "woaijavahahajavaaiwojava";
System.out.println(count(str,"java"));
}
public static int count(String str,String s) {
return (str.length()-str.replace("java","").length())/(s.length());
}
}
|
|