字符串出现的次数

public static int getCount(String str,String sq){
int idx = 0;
int count = 0;
while ((idx = str.indexOf(sq,idx))!=-1){
count++;
idx += sq.length();
}
return count;
}

你可能感兴趣的:(字符串出现的次数)