Getting all key value pairs having the maximum value from a Scala map

前端 未结 2 1031
北荒
北荒 2021-01-23 19:17

I have seen a similar post here here which is giving a single key-value pair which has maximum value in the entire Map.

But I would like to get List of pairs which has m

相关标签:
2条回答
  • 2021-01-23 19:44

    Using map.filter(_._2 == map.values.max) will do the trick.

    0 讨论(0)
  • 2021-01-23 20:05
    val maxValue = map.values.max
    map.filter(_._2 == maxValue).toList
    
    0 讨论(0)
提交回复
热议问题