Android ● ● ○ Kotlin 2.0

Kodebits Day 62: Partition Collection

Jul 22 2026
Practice collections with a short kotlin challenge.

What does this print?

fun main() {
  val xs = listOf(2, 5, 8, 3)
  val (evens, odds) =
    xs.partition { it % 2 == 0 }
  println(evens)
  println(odds)
}


Try it in the online Kotlin Playground →

[spoiler title="Solution"]

Answer:

[2, 8]
[5, 3]

Explanation:

partition splits a collection into a Pair of lists based on a predicate. Elements matching the predicate go in the first list, others in the second.

[/spoiler]


Further Reading