Java Utililty Methods Char Count

List of utility methods to do Char Count

Description

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

Method

ObjectcountCharacterOccurrences(String string, char c)
count Character Occurrences
int result = 0;
int length = string.length();
for (int i = 0; i < length; i++) {
    if (string.charAt(i) == c) {
        result++;
return result;
...
intcountCharacters(String code, char c, int start, int end)
count Characters
int count = 0;
for (int i = start; i < end; i++) {
    if (code.charAt(i) == c) {
        count++;
return count;
intcountCharacters(String str, char chr)
Counts the number of chr's in str.
int ret = 0;
for (int i = 0; i < str.length(); i++) {
    if (str.charAt(i) == chr) {
        ret++;
return ret;
intcountCharInString(String s, char c)
count Char In String
int n = 0;
for (int i = 0; i < s.length(); i++) {
    if (s.charAt(i) == c) {
        n++;
return n;
longcountChars(final String testString, final char match)
count Chars
return testString.codePoints().filter(ch -> ch == match).count();
intcountChars(final String str, final char c)
count Chars
int count = 0;
for (int i = 0; i < str.length(); ++i) {
    if (str.charAt(i) == c) {
        ++count;
return count;
intcountChars(final String str, final char chr)
Counts the number of occurrences of a character in a string.
int count = 0;
boolean isWithinDoubleQuotes = false;
boolean isWithinQuotes = false;
for (int i = 0; i < str.length(); i++) {
    final char c = str.charAt(i);
    if (c == '"' && !isWithinQuotes && !isWithinDoubleQuotes) {
        isWithinDoubleQuotes = true;
    } else if (c == '"' && !isWithinQuotes) {
...
IntegercountChars(final String string, final String findStr)
Returns the number of appearces of "character" in "string".
String strCopy = new String(string);
return strCopy.replaceAll("[" + findStr + "]", "").length();