ankit chaubal wrote:yes i got that! but i have been asked to print only the most highly repeated entry and not the others, whereas here the print statements prints all the entries in the map along with the number of times they are repeated. i have to print just one entry ie the most repeating entry only. how to do that?
You modify the code ! It's not that hard so why don't you have a go rather than just waiting for someone to do it for you. You'll learn much more that way.
Hunter has given you the best advice so far - but I'd go a little further. Forget JAVA all together. Describe, in english, how you personally would find which element in a list occurs the most number of times.
For example, if I needed to sort a list of items, I might do it like this:
read the first element of the list, and remember it.
Read every other element, and see if it any greater than the one i remember, and if so, remember it instead.
when i get to the end of the list, I have the greatest element left in the list.
Write that one down in a NEW list.
Cross it out of the old list
Start over on the old list.
when all the elements are crossed off the old list, the new list is complete and sorted.
So, do the same thing but explain how you would find the element that appears the most number of times in a list. You can use a paper and pencil to keep track of stuff, if you want, but explain what you write down, and how you change it.