Here you can find the source of countOccurences(String textToSearch, String pattern)
public static int countOccurences(String textToSearch, String pattern)
//package com.java2s; /*/* w w w . ja va2 s . c o m*/ * MiscUtil.java * miscellaneous utilities * Copyright (C) 2006 by Institute for Systems Biology, * Seattle, Washington, USA. All rights reserved. * * This source code is distributed under the GNU Lesser * General Public License, the text of which is available at: * http://www.gnu.org/copyleft/lesser.html */ public class Main { public static int countOccurences(String textToSearch, String pattern) { int base = 0; int count = 0; boolean done = false; while (!done) { base = textToSearch.indexOf(pattern, base); if (base > 0) { count++; base += 3; } else done = true; } return count; } }