Kotlin – how to find number of repeated values in a list?

One way to find all the repeated values in a list is using groupingBy and then filter the values which are > 1. E.g.


val list = listOf("orange", "apple", "apple", "banana", "water", "bread", "banana")
println(list.groupingBy { it }.eachCount().filter { it.value > 1 })

Output

{apple=2, banana=2}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)