public class MyClass
{
public static boolean isEmpty(String s) {
return s == null || s.length() == 0;
}
public static int GetOccurrences(String str, String sub) {
if (isEmpty(str) || isEmpty(sub)) {
return 0;
}
return str.split(sub, -1).length - 1;
}
public static void main(String[] args)
{
String str = "DDEEAABCAEEEFDDAAEFFEEEEBA";
String sub = "EE";
int count = GetOccurrences(str, sub);
System.out.println(count);
}
}
/*
run:
4
*/