Java Program to Find the Most Repeated Word in a Text File
Map and Map.Entry interface will be used as the Map interface maps unique keys to values. A key is an object that is used to retrieve a value at a later date. The Map.Entry interface enables you to work with a map entry. Also, we will use the HashMap class to store items in “key/value” pairs and access them by an index of another type.
Suppose the content of the sample text file is as follows:
Input: A text file containing sequence of arbitrary words
“How to count the number of occurrence of each word? How to count number or each word in string. Calculating frequency of each word in a sentence in java.”
Output: List of words that have the maximum occurrencein = 3 each = 3 of = 3 to = 3
Implementation: Sample file input image is as follows:
Time Complexity: O(n)
Auxiliary Space: O(n)
Please Login to comment...