Here you can find the source of countOccurences(String from, String word)
public static int countOccurences(String from, String word)
//package com.java2s; // it under the terms of the GNU Lesser General Public License as published by public class Main { public static int countOccurences(String from, String word) { return (from.length() - from.replace(word, "").length()) / word.length(); }//from w w w . ja v a 2s. c om }