Java Utililty Methods String Char Count

List of utility methods to do String Char Count

Description

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

Method

intcountChar(String string, String c)
count Char
int counter = 0;
for (int i = 0; i < string.length() - (c.length() - 1); i++) {
    boolean check = true;
    for (int j = 0; j < c.length(); j++) {
        if (string.charAt(i + j) != c.charAt(j)) {
            check = false;
            break;
    if (check) {
        counter++;
return counter;
longcountChar(String text, char c)
count Char
return text.chars().filter(e -> c == e).count();
intcountChar(String text, char ch)
count Char
int count = 0;
int length = text.length();
for (int i = 0; i < length; i++)
    if (text.charAt(i) == ch)
        count++;
return count;
intcountChar(StringBuffer sb, char ch)
Count occurrences of character in string buffer.
int result = 0;
for (int i = 0; i < sb.length(); i++) {
    if (sb.charAt(i) == ch)
        result++;
return result;
IntegercountChars(String data)
Counts the number of characters in this String.
if (data == null) {
    return null;
return data.length();
intcountChars(String input)
count Chars
return input.length();
intcountChars(String s, boolean countDigits, boolean countLetters, boolean countOthers)
count Chars
int count = 0;
for (char c : s.toCharArray()) {
    if (Character.isDigit(c)) {
        if (countDigits)
            count++;
    } else if (Character.isLetter(c)) {
        if (countLetters)
            count++;
...
intcountChars(String s, char c)
count Chars
int count = 0;
int index = -1;
while ((index = s.indexOf(c, index + 1)) != -1) {
    count++;
return count;
intcountChars(String s, char c)
Returns the number of occurrences of a char in a string.
int retVal = 0;
for (int i = 0; i < s.length(); i++)
    retVal += s.charAt(i) == c ? 1 : 0;
return retVal;
intcountChars(String s, char c)
count Chars
int cnt = 0;
for (int i = 0; i < s.length(); i++) {
    if (s.charAt(i) == c) {
        cnt++;
return cnt;