Hey I have list of object in which I want to combine title property value into list of object. I did this successfully without any problem. My main questions is there any better approach to do in kotlin which helps in efficient, better memory management and everything when eventList is bigger in size.
CombineList.kt
fun main() {
val newList = mutableListOf<String>()
val eventList = createData()
eventList.forEachIndexed { _, event ->
val title = event.title
if (!title.isNullOrEmpty()) {
newList.add(title)
}
}
println(newList)
}
data class Event(val title: String? = null, val status: String? = null)
fun createData() = listOf(
Event("text 1", "abc"),
Event("text 2", "abc"),
Event("text 3", "abc"),
Event("text 4", "abc"),
Event("", "abc"),
Event(null, "abc")
)