@Test
public void test() {
Map<String, Double> map_Data = new HashMap();
map_Data.put("A", 98.2d);
map_Data.put("B", 50.4d);
map_Data.put("C", 50.2d);
map_Data.put("D", 25.4d);
map_Data.put("E", 85.9d);
System.out.println(map_Data);
List<Map.Entry<String, Double>> list_Data = new ArrayList<Map.Entry<String, Double>>(map_Data.entrySet());
Collections.sort(list_Data, new Comparator<Map.Entry<String, Double>>() {
public int compare(Map.Entry<String, Double> o1, Map.Entry<String, Double> o2) {
if (o2.getValue() != null && o1.getValue() != null && o2.getValue().compareTo(o1.getValue()) > 0) {
return 1;
} else {
return -1;
}
}
});
System.out.println(list_Data);
}
Console Output:
{A=98.2, B=50.4, C=50.2, D=25.4, E=85.9}
[A=98.2, E=85.9, B=50.4, C=50.2, D=25.4]