Here you can find the source of countChar(String src, char c)
public static int countChar(String src, char c)
//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; } }