Here you can find the source of countChars(String s, char c)
public static int countChars(String s, char c)
//package com.java2s; //License from project: Apache License public class Main { public static int countChars(String s, char c) { int cnt = 0; for (int i = 0; i < s.length(); i++) { if (s.charAt(i) == c) { cnt++;/*from w w w . j av a 2s .co m*/ } } return cnt; } public static int countChars(String s, char... chars) { int cnt = 0; for (int i = 0; i < s.length(); i++) { char cs = s.charAt(i); for (char c : chars) { if (cs == c) { cnt++; break; } } } return cnt; } }