07-20-2023, 03:58 PM
I found this:
fun main() {
val list: MutableList<Int> = mutableListOf(1, 2, 3, 4, 5)
list.removeAll { x -> x in 1..3 } // [4, 5]
list.removeIf { x -> x in 1..3 } // [4, 5]
}
Both of them yield the same result.
Though I understand that `removeAll` is Kotlin and `removeIf` is Java but I don't understand why `removeAll` is there when `removeIf` was already there?
And for the fact that we could use `removeIf` in Kotlin without any hassle. Or is there any use case that might need one over another?
fun main() {
val list: MutableList<Int> = mutableListOf(1, 2, 3, 4, 5)
list.removeAll { x -> x in 1..3 } // [4, 5]
list.removeIf { x -> x in 1..3 } // [4, 5]
}
Both of them yield the same result.
Though I understand that `removeAll` is Kotlin and `removeIf` is Java but I don't understand why `removeAll` is there when `removeIf` was already there?
And for the fact that we could use `removeIf` in Kotlin without any hassle. Or is there any use case that might need one over another?