Lobsterrrr Lobsterrrr - 4 months ago 16
Scala Question

How to find most frequent string in List of strings

I have a list of strings (

) and I want to obtain the most frequent string from this list:

val list1 = List('a','a','0','b','b','a')

The answer should be:

freq_list1 = a

I was thinking to use
in order to get the count of unique string, but I don't know how to wrap it into finding the most frequent string.


EDIT: See comment below, can be made shorter by using maxBy(_._2.size) without mapping beforehand, thanks @kawty