Reputation: 251
I would like to write a program in JAVA, to capture words which repeated more than 2 times in a text content.
for instance: the blue book over The red pen is the biggest book I ever seen. Result: the:3
What can be the proper regular expression pattern for this matter?
Upvotes: 0
Views: 264
Reputation: 785186
Rather than trying to solve this problem by regex I would suggest following algorithm:
List<String>
.HashMap<String, Integer>
.List
and keep storing in the map.Map
didn't have an entry of the word then key=word, value=1
HashSet<String>
HashSet<String>
Upvotes: 1
Reputation: 148930
There is no need for regexes, unless for splitting a text in words. Next you just have to use a Map, with the key being the word, and value being the number or repetitions.
When done, you just scan the Map to find the most repeated word.
Upvotes: 0