apache commons lang包中的StringUtils

计算一个字符串某个字符的出现次数
a, 使用charAt方法截取之后,循环判断.
b, 使用apache commons lang包中的StringUtils:
int n = StringUtils.countMatches("ababababab", "a");
System.out.println(n);


如何使一个字符串重复N次。
API提供了一个非常好的方法。String str = "ab";
String repeated = StringUtils.repeat(str,3);//输出的结果是ababab,三次重复.

  

posted @ 2017-06-07 12:18  ATJAVA  阅读(364)  评论(0编辑  收藏  举报