public static int count(String str, String target) {
return (str.length() - str.replace(target, "").length()) / target.length();
}
String line = "apples.oranges.bananas";
int count = line.length() - line.replace(".", "").length();
System.out.println(count);//displays 2