【Java学习】获取一个字符串在另一个字符串出现的次数
时间:2014-08-29 11:15:28
收藏:0
阅读:192
public class StringCount {
public static void main(String[] args) {
String ss = "kkabkkcdkkefkkskk";
String key = "kk";
System.out.println(getSubCount_2(ss,key));
}
public static int getSubCount_2(String str,String key) {
int count = 0 ;
int index = 0 ;
while ((index = str.indexOf(key)) != -1) {
System.out.println(str);
str = str.substring(index+key.length());
count++;
}
return count ;
}
}本文出自 “azhome” 博客,请务必保留此出处http://azhome.blog.51cto.com/9306775/1546368
评论(0)