Count all occurances of a particular word
How can I read a string and count all occurances of a particular word? I tried that but can't find any solution. Please help me by examining my code that attached with this post.
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.


Guest UserRank #259 · 9.8K reputationPosted Jul 8, 2014, 7:01 PM EDT
I found one easy example in JAVA ecosystem
http://runnable.com/UqUJWzqM7L8-AAFT/how-to-count-the-number-of-matching-string-in-java-for-regex
twitter @sumitjolly
Abhijeet SinghRank #415 · 6K reputationPosted Mar 28, 2015, 8:34 PM EDT
http://www.avajava.com/tutorials/lessons/how-do-i-count-the-occurrences-of-a-string-in-another-string.html
Joginder BangerRank #360 · 7K reputationPosted Mar 29, 2015, 1:12 AM EDT
Matcher m = p.matcher("abba is abba with abbabba and abba doing abba");
int count = 0;
while(m.find()){ count++; }
System.out.println(count); //4