Http://outofmemory.cn/code-snippet/815/java-zishutongji
An API, located under the Apache.commons.lang.StringUtils class, under a stringutils.countmatches (paragraph, string); method, the return value of this method is a numberCode: Package cn.outofmemory;
Import Org.apache.commons.lang3.StringUtils;
public class WordCounter {
public static void Main (string[] args) {
String with our paragraph
String paragraph = "Java Code Geeks (JCGS) is a independent online community focused on creating the"
+ "Ultimate Java-to-java developers Resource Center; Targeted at the technical architect, technical "
+ "Team Lead (senior developer), Project manager and junior developers alike. Jcgs serve the Java, "
+ "Scala, Android, SOA, Agile and Telecom communities with daily News written by domain experts,"
+ "articles, tutorials, reviews, announcements, code snippets and open source projects.";
Declare the word want to search
String string = "Java";
Count Word repetitions
int counter = stringutils.countmatches (paragraph, string);
Print the result
System.out.println ("Word <" + string + "> Appeared "+ Counter +" times in the paragraph. ");
}
}
Java implementation Statistics The number of occurrences of a piece of text in the content