Returns a collection containing only elements matching the given predicate.
Syntax
collection.filter { predicate }Example
Enter values below to update the example in real time.
val→nums→listOf→result→filter→it→map→println→val nums = listOf(1, 2, 3, 4, 5, 6)
val result = nums.filter { it % 2 == 0 }.map { it * it }
println(result) // [4, 16, 36]