fun main() {
var list1 = listOf("AAAA", "ASAS", "ADDAD", "AS")
var list2 = list1
println(list2 === list1)
list2 = list2
.filter { it.length >= 3 }
println(list2 === list1)
}
The output of above code is:
true
false
But I am confused why list1 is not being modified since both list1 and list2 are referencing to same list object first. Can anyone please help me understand what exactly is going on here?