Java获取指定字符串出现次数的方法
Java中获取指定字符串在另一个字符串中出现的次数,供大家参考,具体内容如下
/**
*@paramargs
*/
publicstaticvoidmain(String[]args){
StringsrcText="HelloWorld";
StringfindText="e";
intnum=appearNumber(srcText,findText);
System.out.println(num);
}
/**
*获取指定字符串出现的次数
*
*@paramsrcText源字符串
*@paramfindText要查找的字符串
*@return
*/
publicstaticintappearNumber(StringsrcText,StringfindText){
intcount=0;
Patternp=Pattern.compile(findText);
Matcherm=p.matcher(srcText);
while(m.find()){
count++;
}
returncount;
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短