I have to make a program: read a file from the hard disk and count the number of words in the file. The programmer must then print the words along with the number of times the
word has occured in the file in order of their occurence.
I have counted the number of times the word has occured in the file but I am not able to print them in ascending order of their occurence. For e.g. if words are:
'student' occured 2 times
'child' occured 1 time
'parent' occured 1 time, then the output should be
child: 1
parent :1
student :2
I think map can be the best way to store this. I tried using TreeMap so that it can store the key ( number of occurence) in ascending order. But it does not store duplicate keys!!!
I mean my output is coming as:
child: 1
student :2
the entry :
parent :1
is missing as the key "1" is duplicate.
How can I maintain duplicate keys in map so that I can use them in ascending order?