What is the best way to deepcopy a list, I am usin...
# getting-started
a
What is the best way to deepcopy a list, I am using the following way
studentList.forEach {
if(it.id ==student.id){
list.add(it.copy(isFailed = false))
}else{
list.add(it)
}
}
k
You can also use map:
Copy code
val newList = studentList.map {
    if (it.id == student.id) {
        it.copy(isFailed = false)
    } else {
        it
    }
}
🥇 1
a
Is there any performance implication as forEach does not return any list its a plain void whereas map transforms a list
z
you are already creating a new list above your forEach anyway, so no
👍 2