Here you can find the source of countChar(String s, char c)
public static int countChar(String s, char c)
//package com.java2s; public class Main { /** Count the number of times a given character occurs in a String: */ //@ ensures \result>=0; public static int countChar(/*@non_null*/String s, char c) { int count = 0; int start = 0; while ((start = s.indexOf(c, start) + 1) != 0) count++;/*from w w w. jav a2 s.c om*/ return count; } }