Kotlin - how to find number of repeated values in a list?
问题 I have a list, e.g like: val list = listOf("orange", "apple", "apple", "banana", "water", "bread", "banana") How can i check how many times apple is duplicated in this list? 回答1: list.count { it == "apple" } Documentation: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/, https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/count.html 回答2: 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