I have a small HashMap (less than 100 entries) that contains a unique object (of my design) as the key and a Double as the value.
I need to retrieve n number of objects that have the lowest values.
So say my HashMap looked like this and I wanted the lowest 3.
Object, 4.0
Object, 5.0
Object, 2.0
Object, 12.0
Object, 10.0
Object, 3.0
I would want to fetch the first, third, and last entries as those have the lowest values.
I know there are methods such as Collections.min which I could run on the HashMap but I need more than just the lowest value and I need to know the key it corresponds to as well. Research has also led me to come across Selection Algorithms but I am confused and not quite sure how to use these. I apologise if a question of this sort has been asked before, I searched for a long time and could not find anything. Thanks pre-emptively for your help.