Change a value in mutable list in Kotlin
You can use find
function to find the element with id = 2 and change its property:
vids?.find { it.id == 2 }?.iLike = true
Note: it is a good practice to use question mark if the property is nullable and you unsure whether it is null or not.
Try this, I'm assuming your Videos
structure is a data class defined somewhat like so. data class Videos(val id: Int, val yt_id: String, val title: String, val likes: Int, val kat: String, val ilike: Boolean)
list.forEachIndexed { index, video -> video.takeIf { it.id == 2}?.let { list[index] = it.copy(ilike = true) }}