Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to count a frequency of a particular word in a line?

Tags:

java

string

I would like to know, that if I am having a single line string, then how to count the frequency of a particular word in that string, using simple java code?!

Thanks in advance..


What I am looking for is a sample logical code in java which is used to search a particular word in a sentence. I am building one spam filter, which needs to read the line and then classify it.

like image 505
Maverick Avatar asked Dec 01 '22 09:12

Maverick


1 Answers

StringUtils from commons-lang has:

StringUtils.countMatches(string, searchedFor);
like image 124
Bozho Avatar answered Dec 31 '22 06:12

Bozho