使用Apache Commons Lang包中的 StringUtils类就可以完成这个工作。

int n= StringUtils.countMatches("aaaaabbbbbcccccc","c");
System.out.println("n="+n);

  

  计算结果:

  n=6

posted on 2017-04-27 13:49  houxiurong.com  阅读(410)  评论(0编辑  收藏  举报
< a href="http://houxiurong.com">houxiurong.com