I have a hashmap containing <String, integer>
, with entries such as:
("a",2)
("ab", 3)
("c",5) etc..
I have seen questions where they find the single largest value and store it in another hashmap, but how would I be able to loop that so that the "n" largest numbers can be found and put in the result hash map
e.g for the above hashmap entries, if n was 2, it would find the 2 largest values and put in the result hashmap
("ab", 3)
("c", 5)
Thank you very much in advances.