I have A simple case where I Have "List A" with 5 values and another "List B" acts As TempList holding "List A" values now when I call "list_A.clear()"
"list_B" also get Cleared why?
val List_A: MutableList<String> = ArrayList<String>() List_A.add("index_1") List_A.add("index_2") List_A.add("index_3") List_A.add("index_4") List_A.add("index_5") val List_B = List_A List_A.clear() Result
List_A-----Size--------> 0 List_B-----Size--------> 0 Please Note that it works as expected when I define "List_B" as
var List_B: MutableList<String> = ArrayList<String>() then List_B.addAll(List_A) Result
List_A-----Size--------> 0 List_B-----Size--------> 5 Does kotlin passes List_A variable Referance to List_B ?