I would need to sort a list of words based on its frequency.
My input:
Haha, hehe, haha, haha, hehe, hehe.... , Test
For example in my data structure I would have
Haha:3
Hehe:5
Test:10
I would need the data structure to be sorted at the output in this manner:
Test:10
Hehe:5
Haha:3
Such that if I pop the top of the data structure I would be able to obtain the element and its corresponding frequency.
The number of elements is unknown initially and hence, an array would not be feasible. If I would like to obtain the top few elements I would just need to access it sequentially. Is this possible in Java?