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.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Joginder BangerPosted Mar 29, 2015, 5:12 AM
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
Abhijeet SinghPosted Mar 29, 2015, 12:34 AM
http://www.avajava.com/tutorials/lessons/how-do-i-count-the-occurrences-of-a-string-in-another-string.html
Guest UserPosted Jul 8, 2014, 11:01 PM
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