Here you can find the source of countMatches(String string, char toMatch)
Parameter | Description |
---|---|
string | the string to test |
toMatch | the character to look for |
protected static int countMatches(String string, char toMatch)
//package com.java2s; //License from project: Open Source License public class Main { /**//from w ww . j a v a2 s . c om * Count the number of times a specific character is present in a string * * @param string * the string to test * @param toMatch * the character to look for * @return the number of times toMatch is present in string */ protected static int countMatches(String string, char toMatch) { int occurrences = 0; for (char c : string.toCharArray()) { if (c == toMatch) { occurrences++; } } return occurrences; } }