Get minvalue of a Map(Key,Double)

前端 未结 9 1974
一个人的身影
一个人的身影 2020-12-05 07:08

Is there a method (maybe with Google Collections) to obtain the min value of a Map(Key, Double)?

In the traditional way, I would have to sort the map ac

9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-05 07:46

    Using java 8 (and static imports). We can make @superfav's solution much tidier:

    Map myMap;
    String theKeyWithHighestValue = Collections.min(myMap.entrySet(), comparingDouble(Entry::getValue)).getKey()
    

提交回复
热议问题