Here you can find the source of countMatches(String str, String match)
Parameter | Description |
---|---|
str | The String to be searched |
match | The String to be searched for |
public static int countMatches(String str, String match)
//package com.java2s; //License from project: MIT License public class Main { /**//from w w w . ja v a 2 s . c o m * Counts the occurence of a String in another String * * @param str * The String to be searched * @param match * The String to be searched for * @return How often the searched string has been found */ public static int countMatches(String str, String match) { int counter = 0; while (str.contains(match)) { counter++; str = str.substring(str.indexOf(match) + match.length()); } return counter; } }