Count wornds java example
public static int countWords(String str, String findStr){ int lastIndex = 0; int count =0; while(lastIndex != -1){ lastIndex = str.indexOf(findStr,lastIndex); if( lastIndex != -1){ count ++; } if (lastIndex==-1) break; lastIndex+=findStr.length(); } return count ; }