I have an Activity A
which has:
class ActivityA {
companion object {
var list: MutableList<Person> = //objects are acquired here.
}
}
In ActivityB
, I copy this list to a variable.
class ActivityB {
var copyList: MutableList<Person> = ActivityA.list.toMutableList()
}
After that I am changing some data of the copyList
. For example, let's change name of any element. Let's say original list
has list.get(0).name = "Bruno"
. Now, change to something else.
copyList.get(0).name = "Alex"
Problem is this is also causing the element at index 0 to be also changed in list
. Which means list.get(0).name
and copyList.get(0).name
has the same names "Alex" now.
How can I make sure that original list
elements are not changed even though copyList
elements are changed?