Вы все еще можете использовать Collections.min
с пользовательским Comparator
, чтобы получить Map.Entry
с меньшим значением:
Map<String, Double> map = new HashMap<String, Double>();
map.put("1.1", 1.1);
map.put("0.1", 0.1);
map.put("2.1", 2.1);
Entry<String, Double> min = Collections.min(map.entrySet(), new Comparator<Entry<String, Double>>() {
public int compare(Entry<String, Double> entry1, Entry<String, Double> entry2) {
return entry1.getValue().compareTo(entry2.getValue());
}
});
System.out.printf("%s: %f", min.getKey(), min.getValue()); // 0.1: 0.100000
С Java 8:
Entry<String, Double> min = Collections.min(map.entrySet(),
Comparator.comparing(Entry::getValue));