Java String Char Count countChar(String str, char c)

Here you can find the source of countChar(String str, char c)

Description

count Char

License

Open Source License

Declaration

public static int countChar(String str, char c) 

Method Source Code

//package com.java2s;

public class Main {
    public static int countChar(String str, char c) {
        if (str == null || str.isEmpty())
            return 0;
        final int len = str.length();
        int cnt = 0;
        for (int i = 0; i < len; ++i) {
            if (c == str.charAt(i)) {
                ++cnt;/*w  ww .  ja  v  a2  s .  c  o m*/
            }
        }
        return cnt;
    }

    public static boolean isEmpty(String str) {
        return ((str == null) || (str.length() == 0));
    }
}

Related

  1. countChar(String s, char c)
  2. countChar(String s, char c)
  3. countChar(String s, char c)
  4. countChar(String sql, int end)
  5. countChar(String src, char c)
  6. countChar(String str, char c)
  7. countChar(String str, char chr)
  8. countChar(String str, char reg)
  9. countChar(String string, char c, int pos, boolean forwards)