當前位置:編程學習大全網 - 電腦編程 - java中怎麽確定壹個字符串在另壹個字符串中出現的次數

java中怎麽確定壹個字符串在另壹個字符串中出現的次數

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);

  • 上一篇:輪轂中心孔大怎麽固定墊圈?
  • 下一篇:TX3219A碼無法編碼。
  • copyright 2024編程學習大全網