substring all occurrences code example
Example: 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();
}
public static int count(String str, String target) {
return (str.length() - str.replace(target, "").length()) / target.length();
}