1.出現多少次:
判斷某個字符有幾個
String a = “abbdfsads”;
int n = a.length()-a.replaceAll(“a”, “”).length();
System.out.println(“字符串中字符a有”+n+“個”);
原文:
https://zhidao.baidu.com/question/1899190409868380700.html
2.出現的所有索引位置:
int a = str.indexOf(key);//*第一個出現的索引位置
while (a != -1) {
System.out.print(a + “\t”);
a = str.indexOf(key, a + 1);//*從這個索引往後開始第一個出現的位置
}
轉載於:
原文:https://blog.csdn.net/eyishion/article/details/65943129