举例如下:
String str1 = "nihaoksdoksad";
String str2 = "ok";
int total = 0;
for (String tmp = str1; tmp != null&&tmp.length()>=str2.length();){
if(tmp.indexOf(str2) == 0){
total ++;
}
tmp = tmp.substring(1);
}
System.out.println(str1+"中含有"+total+"个"+str2);