假设要得到字符串B在字符串A中出现的次数:
//假设字符串A和B已声明并赋值
int count=0;
int fromIndex=0;
while(fromIndex!=-1){
fromIndex=A.indexOf(B,fromIndex);
if(fromIndex!=-1){
fromIndex+=B.length();;
count++;
}
}
System.out.println(count);
原文地址:http://blog.csdn.net/listener_ri/article/details/45999729