java String 怎么看里面有几个指定字符

我现在有一个String 字符串,我想看一下这个字符串里有几个指定的字符,比如指定字符是div求解
public class Main {

    public static void main(String[] args) {
RrdDef rrdDef;
RrdDb rrdDb;
String str = "divabcdivbbdivcdivdde",
des = "div"; int cnt = 0;
int offset = 0;
while((offset = str.indexOf(des, offset)) != -1){
offset = offset + des.length();
cnt++;
}
System.out.println(cnt);
}
}
上一篇:Python财经数据接口包TuShare的使用


下一篇:学习ML.NET(1): 构建流水线