public static int countString(String minstr,String maxstr){
int len1 = minstr.length();
int count = 0;
int index = maxstr.indexOf(minstr);
while(index != -1){
count++;
maxstr = maxstr.substring(index + len1,maxstr.length());
index = maxstr.indexOf(minstr);
}
return count;
}
改进
while((index = maxstr.indexOf(minstr,maxstr)) != -1){
count++;
index = maxstr.indexOf(minstr);
}
return count;