我有Map[String,String]这样的键是不同的,但大多数值是重复的.例如 :Map[car-> "This is a car",truck-> "This is a car", fruit ->"This is a fruit"]
因此它应该返回,"This is a car"因为它重复两次.
我做了这样的事.希望能帮助到你.
val j = x.groupBy(_._2)
Run Code Online (Sandbox Code Playgroud)
然后
j.maxBy(_._2.size)
Run Code Online (Sandbox Code Playgroud)
其中x是您的原始地图.第一个调用,返回一个Map,然后你只需得到键值对(map,有max条目)