Java Utililty Methods String Match Count

List of utility methods to do String Match Count

Description

The list of methods to do String Match Count are organized into topic(s).

Method

intcountMatches(CharSequence str, CharSequence sub)

Counts how many times the substring appears in the larger string.

if ((str == null || str.length() == 0) || (sub == null || sub.length() == 0)) {
    return 0;
int count = 0;
int idx = 0;
while ((idx = indexOf(str, sub, idx)) != -1) {
    count++;
    idx += sub.length();
...
intcountMatches(final CharSequence seq, final char c)
count Matches
if (isEmpty(seq))
    return 0;
int count = 0;
for (int i = 0; i < seq.length(); i++) {
    if (seq.charAt(i) == c)
        count++;
return count;
...
intcountMatches(final CharSequence str, final char ch)

Counts how many times the char appears in the given string.

if (isEmpty(str)) {
    return 0;
int count = 0;
for (int i = 0; i < str.length(); i++) {
    if (ch == str.charAt(i)) {
        count++;
return count;
intcountMatches(final CharSequence str, final CharSequence sub)
count Matches
if (isEmpty(str) || isEmpty(sub)) {
    return 0;
int count = 0;
int idx = 0;
while ((idx = str.toString().indexOf(sub.toString(), idx)) != INDEX_NOT_FOUND) {
    count++;
    idx += sub.length();
...
intcountMatches(final CharSequence str, final CharSequence sub)
count Matches
if (isEmpty(str) || isEmpty(sub)) {
    return 0;
int count = 0;
int idx = 0;
while ((idx = indexOf(str, sub, idx)) != INDEX_NOT_FOUND) {
    count++;
    idx += sub.length();
...
intcountMatches(final CharSequence str, final CharSequence sub)
Counts how many times the substring appears in the larger string.
if (isEmpty(str) || isEmpty(sub)) {
    return 0;
int count = 0;
int idx = 0;
while ((idx = indexOf(str, sub, idx)) != -1) {
    count++;
    idx += sub.length();
...
intcountMatches(final String str, final String sub)
count Matches
if (isEmpty(str) || isEmpty(sub)) {
    return 0;
int count = 0;
int idx = 0;
while ((idx = str.indexOf(sub, idx)) != -1) {
    count++;
    idx += sub.length();
...
intcountMatches(String line, char chr)
count Matches
return line.length() - line.replace(String.valueOf(chr), "").length();
intcountMatches(String reference, String query)
count Matches
int count = reference.length() - reference.replaceAll(query, "").length();
return count;
intcountMatches(String s, String sb)
Retrieve how many times is the substring in the larger string.
if (s == null || sb == null) {
    return 0;
int count = 0;
int idx = 0;
while ((idx = s.indexOf(sb, idx)) != -1) {
    count++;
    idx += sb.length();
...