You should be able to utilize the StringUtils
class and the countMatches()
method.
public static int countMatches(String str, String sub)
Counts how many times the substring appears in the larger String.
Try the following:
int count = StringUtils.countMatches("a.b.c.d", ".");