How to get min by value only in Scala Map

前端 未结 2 1769
走了就别回头了
走了就别回头了 2021-02-05 13:12

I have a map that has SomeClass -> Double I want to get the SomeClass associated with the smallest value. How do I go about doing this? Ties do not

2条回答
  •  时光说笑
    2021-02-05 13:30

    Use minBy:

    Map("a" -> 3.0, "b" -> 1.0, "c" -> 2.0).minBy(_._2)._1
    

    This gives "b" as expected.

提交回复
热议问题