Android ● ○ ○ Kotlin 2.3

Kodebits Day 19: Count With Predicate

May 8 2026
Practice collections with a short kotlin challenge.

What does this print?

fun main() {
  val xs = listOf(8, 4, 1, 2)
  println(xs.count { it > 5 })
}


Try it in the online Kotlin Playground →

[spoiler title="Solution"]

Answer:

1

Explanation:

count returns how many elements satisfy the predicate. Here only one (8) is greater than 5.

[/spoiler]


Further Reading