Here you can find the source of charCount(String str, char sub)
public static int charCount(String str, char sub)
//package com.java2s; public class Main { public static int charCount(String str, char sub) { int charCount = 0; int fromIndex = 0; while ((fromIndex = str.indexOf(sub, fromIndex)) != -1) { fromIndex++;/* w w w. j av a2s . c o m*/ charCount++; } return charCount; } }