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

前端 未结 2 1739
暗喜
暗喜 2021-02-02 07:15

I have a list, e.g like:

val list = listOf(\"orange\", \"apple\", \"apple\", \"banana\", \"water\", \"bread\", \"banana\")

How can i check how

2条回答
  •  一个人的身影
    2021-02-02 08:01

    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

提交回复
热议问题