0Pricing
Kotlin Academy · Lesson

Filtering and Mapping

Transform collections.

Transforming Collections

Kotlin collections come with a rich set of functional operations. Two of the most common are filter (select elements) and map (transform elements). They return new collections and never modify the original.

The filter Function

filter keeps only the elements that satisfy a predicate, returning a new list.

fun main() {
    val numbers = listOf(1, 2, 3, 4, 5, 6)
    val evens = numbers.filter { it % 2 == 0 }
    println(evens)
}

All lessons in this course

  1. Filtering and Mapping
  2. Grouping and Partitioning
  3. Aggregation
  4. Association and Flattening
← Back to Kotlin Academy