public class Test {
/**
* 需求:统计大串中小串出现的次数
* 这里的大串和小串可以自己根据情况给出
*/
public static void main(String[] args) {
String max = "woaiheima,heimabutongyubaima,bulunheimabaima,zhaodaogongzuojiushihaoma";
String min = "ma";
int count = 0;
for (int i = 0;(i = max.indexOf(min)) != -1 ;i++ ) {
max = max.substring(i + min.length());
count++;
}
System.out.println(count);
}
|
|