September 2019
Intermediate to advanced
816 pages
18h 47m
English
A simple solution to this problem consists of the following two steps:
The code for this method is as follows:
public static int countOccurrencesOfACertainCharacter( String str, char ch) { return str.length() - str.replace(String.valueOf(ch), "").length();}
The following solution covers Unicode surrogate pairs as well:
public static int countOccurrencesOfACertainCharacter( String str, String ch) { if (ch.codePointCount(0, ...