Here you can find the source of countOccurences(String text, String target)
Parameter | Description |
---|---|
text | the String to search |
target | the String to search for |
public static int countOccurences(String text, String target)
//package com.java2s; //License from project: BSD License public class Main { /**//ww w .j a v a 2 s . c o m * Counts the number of occurrences of a String within another String. * * @param text the String to search * @param target the String to search for * @return the number of occurrences of target within text */ public static int countOccurences(String text, String target) { return text == null || target == null || !text.contains(target) ? 0 : 1 + countOccurences(text.substring(text.indexOf(target) + 1), target); } }