java get number of times a string is in another string code example
Example 1: how to test how many of one character is in a string java
int count = string.length() - string.replaceAll("g","").length()
Example 2: find number of occurrences of a substring in a string java
public static int count(String str, String target) {
return (str.length() - str.replace(target, "").length()) / target.length();
}