Kotlin List filter Filtering is an operation where only elements that meet certain criteria pass through.
Kotlin List filter Example
The example presents the filtering operation on Kotlin lists.
package net.sourcecodeexamples.kotlin
fun main(args: Array<String>) {
val fruits = listOf("banana", "mango", "apple", "orange")
val fruits1 = fruits.filter { e -> e.length == 5 }
fruits1.forEach { e -> print("$e ") }
println()
val fruits2 = fruits.filterNot { e -> e.length == 5 }
fruits2.forEach { e -> print("$e ") }
println()
}
Output:
mango apple
banana orange
Free Spring Boot Tutorial - 5 Hours Full Course
Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course