Apache Commons Lang – StringUtils(CountMatches)
引き続き、StringUtilsクラスの説明です。
今回は、文字列の出現数についてです。
countMatches
public static int countMatches(java.lang.String str, java.lang.String sub)
検索対象の文字列の中で、指定された文字列が出現した数を取得します。
検索対象の文字列にNULL、または空文字が指定された場合は、0を返却します。
検索する文字列にNULL、または空文字が指定された場合は、0を返却します。
- パラメータ:
str
– 検索対象の文字列
sub
– 検索する文字列
- 戻り値:
- 検索対象の文字列の中で、指定された文字列が出現した数
StringUtils.countMatches(null, "a") = 0 StringUtils.countMatches("", "a") = 0 StringUtils.countMatches("abba", null) = 0 StringUtils.countMatches("abba", "") = 0 StringUtils.countMatches("abba", "a") = 2 StringUtils.countMatches("abba", "ab") = 1 StringUtils.countMatches("abba", "xxx") = 0
関連記事
- Apache Commons Lang – StringUtils(IndexOfAny / LastIndexOfAny / IndexOfAnyBut / LastIndexOfAnyBut)
- Apache Commons Lang – StringUtils(DefaultString)
- Apache Commons Lang – StringUtils(UpperCase / LowerCase / SwapCase / Capitalize / Uncapitalize)
- Apache Commons Lang – StringUtils(IndexOf / LastIndexOf / Contains)
- Apache Commons Lang – StringUtils(Reverse / ReverseDelimited)
コメント 0