Here you can find the source of countChars(String s, char c)
Parameter | Description |
---|---|
s | String to be analyzed |
c | Char to be counted |
c
in s
public static int countChars(String s, char c)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from w ww . j a v a2 s .c om*/ * Returns the number of occurrences of a char in a string. * @param s String to be analyzed * @param c Char to be counted * @return The number of occurrences of <code>c</code> in <code>s</code> */ public static int countChars(String s, char c) { int retVal = 0; for (int i = 0; i < s.length(); i++) retVal += s.charAt(i) == c ? 1 : 0; return retVal; } }