public static int countOccurance (String word, String sentence) { Pattern pattern = Pattern.compile(word ,Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(sentence); int count = 0; while (matcher.find()) count++; return count; }