public static int countMatches(CharSequence str,CharSequence sub){
  if (isEmpty(str) || isEmpty(sub)) {
    return 0;
  }
  int count=0;
  int idx=0;
  while ((idx=indexOf(str,sub,idx)) != INDEX_NOT_FOUND) {
    count++;
    idx+=sub.length();
  }
  return count;
}

public static int countMatches ( CharSequence str , CharSequence sub ) { if ( isEmpty ( str ) || isEmpty ( sub ) ) { return 0 ; } int count = 0 ; int idx = 0 ; while ( ( idx = indexOf ( str , sub , idx ) ) != INDEX_NOT_FOUND ) { count ++ ; idx += sub . length ( ) ; } return count ; }
counts how many times the substring appears in the larger string .
