Here you can find the source of countChars(String s, char c)
private static int countChars(String s, char c)
//package com.java2s; //License from project: Open Source License public class Main { private static int countChars(String s, char c) { int count = 0; int index = -1; while ((index = s.indexOf(c, index + 1)) != -1) { count++;//from w w w.j a v a 2 s .c o m } return count; } }