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

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

Description

count Char

License

Apache License

Declaration

public static int countChar(String src, char c) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static int countChar(String src, char c) {
        if (isNullOrNone(src)) {
            return 0;
        }/*from   www .  j a  v a 2  s  . c o m*/

        int k = 0;
        for (int i = 0; i < src.length(); i++) {
            if (src.charAt(i) == c) {
                k++;
            }
        }

        return k;
    }

    public static boolean isNullOrNone(String s) {
        if (s == null || "".equals(s.trim())) {
            return true;
        }

        return false;
    }

    public static boolean isNullOrNone(Object obj) {
        if (obj == null) {
            return true;
        }
        if (obj instanceof String) {
            return isNullOrNone((String) obj);
        }
        return false;
    }

    public static boolean isNullOrNone(String[] ss) {
        if (ss == null || ss.length == 0) {
            return true;
        }

        for (int i = 0; i < ss.length; i++) {
            if (ss[i] == null || "".equals(ss[i].trim())) {
                return true;
            }
        }

        return false;
    }
}

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 str, char c)
  6. countChar(String str, char c)
  7. countChar(String str, char chr)
  8. countChar(String str, char reg)