0Pricing
Kotlin Academy · Lesson

filter, map, and find on Collections

Apply lambdas to transform and filter collections using standard library functions.

Three Workhorse Functions

filter keeps elements matching a predicate. map transforms each element. find returns the first matching element (or null). Together they cover the bulk of collection processing.

filter Basics

filter returns a new list containing only elements for which the predicate is true.

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

All lessons in this course

  1. What Is a Lambda? Syntax and Types
  2. Passing Lambdas to Functions
  3. it: The Implicit Parameter
  4. filter, map, and find on Collections
← Back to Kotlin Academy