First of all let me say, please dont answer this by saying "just use a TreeMap" I am aware of TreeMaps but specifically want to learn if the following is possible.
In Java, lets say I have a HashMap of Strings which map to Doubles.
Map<String, Double> map = new HashMap<String, Double>();
And I have inserted some key value pairs into this map. Now let's say I get the keySet:
Collection<String> keys = map.keySet();
My question is, how do I sort the keys collection by the corresponding values in the map? In Perl this would read something like this:
my @keys = sort { $hash{$a} <=> $hash{$b} } keys %hash;
Is there a way to do exactly this in Java using a HashMap?