I have a hashmap of objects. Each object has two attributes (let say int length and int weight).
I want to remove k elements with the smallest length.
What is the efficient way of doing this?
I have a hashmap of objects. Each object has two attributes (let say int
Share
Where
Kis your key type,Vis your value type, andnumis the number of elements you wish to remove.If you are doing this frequently, it might be a good idea to use a
TreeMapin the first place.