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