Description | A Java program to read a text file and print each of the unique words in alphabetical order together with the number of times the word occurs in the text.
The program should declare a variable of type Map<String, Integer>
to store the words and corresponding frequency of occurrence. Which concrete type, though? TreeMap<String, Number>
or HashMap<String, Number>
?
The input should be converted to lower case.
A word does not contain any of these characters: \t\t\n]f.,!?:;\"()'
Example output |
Word Frequency
a 1
and 5
appearances 1
as 1
.
.
.
Remark | I know, I've seen elegant solutions to this in Perl with roughly two lines of code. However, I want to see it in Java.
Edit: Oh yeah, it be helpful to show an implementation using one of these structures (in Java).