public static int countOccurrences(String fullString,String pattern){
  int lastIndex=0;
  int count=0;
  while (lastIndex != -1) {
    lastIndex=fullString.indexOf(pattern,lastIndex);
    if (lastIndex != -1) {
      count++;
      lastIndex+=pattern.length();
    }
  }
  return count;
}

public static int countOccurrences ( String fullString , String pattern ) { int lastIndex = 0 ; int count = 0 ; while ( lastIndex != - 1 ) { lastIndex = fullString . indexOf ( pattern , lastIndex ) ; if ( lastIndex != - 1 ) { count ++ ; lastIndex += pattern . length ( ) ; } } return count ; }
counts the occurrences of a particular pattern in the string .
