import java.util.*; /** * Count frequency of words occurring in a string */ class MapExample { workMap(strr); } /* 'frequency' is the count of the words. For a new word getting added to the Map, we set its frequency as 1. For existing words, we take their existing frequency (value in the map) and increment it and put back into the map correspondint to that word (key in the map) */ map.put(word, frequency); } } }
Standard input is empty
Unsorted: {hello=1, is=1, life=1, are=1, how=2, am=1, into=1, you=1, ascent=1, world=1, i=1} Sorted: {am=1, are=1, ascent=1, hello=1, how=2, i=1, into=1, is=1, life=1, world=1, you=1}