We can filter a list based on specified predicate and create a new list using the filter()
function :
// Syntax :
coll.filter { /* Predicate */ }
Example :
fun main() {
val nums = -2..2
val negatives = nums.filter { it < 0 }
println(negatives)
}
// Output : [-2, -1]