Java Utililty Methods String Match Count

List of utility methods to do String Match Count

  1. HOME
  2. Java
  3. S
  4. String Match Count

Description

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

Method

int countMatches(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();
...
int countMatches(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;
...
int countMatches(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;
int countMatches(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();
...
int countMatches(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();
...
int countMatches(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();
...
int countMatches(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();
...
int countMatches(String line, char chr)
count Matches
return line.length() - line.replace(String.valueOf(chr), "").length();
int countMatches(String reference, String query)
count Matches
int count = reference.length() - reference.replaceAll(query, "").length();
return count;
int countMatches(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();
...


AltStyle によって変換されたページ (->オリジナル) /