I was thinking maybe HashMap, but that doesn't allow sorting. Maybe list? I honestly have no clue. I've been struggling with this a lot.
Strings: "Tom", "Sarah", "Oliver". Values: 323, 237.2, 12.1
I was thinking maybe HashMap, but that doesn't allow sorting. Maybe list? I honestly have no clue. I've been struggling with this a lot.
Strings: "Tom", "Sarah", "Oliver". Values: 323, 237.2, 12.1
You can use entries with Key and Value like you would do in a hash table but add that entries to a Priority Queue that must be created with the comparator you want.
Here is an example: How do I use a PriorityQueue?
In that case the comparator is created to compare string lengths but you can change that to compare the value of an entry.
The difference is that you have to create the PriorityQueue as new PriorityQueue> instead of new PriorityQueue
Hopes it helps