Mega Code Archive

 
Categories / Java / Data Type
 

Count word occurrences in a string

import org.apache.commons.lang.StringUtils; public class Main {   public static void main(String[] args) {     String source = "this is a test";     String word = "is";     int wordFound = StringUtils.countMatches(source, word);     System.out.println(wordFound);   } }