I have a list of actions object. I am trying to make it a list of string on basis of action type
Sample data
{
"wicked": "not at all",
"footer": {
"actions": [
{
"icon": "",
"type": "click"
},
{
"icon": "",
"type": "click"
},
{
"icon": "",
"type": "click"
}
]
}
}
These are my data classes
data class Footer(
val actions: List<Actions>?)
data class Actions(
val copy: String?,
val action: String?)
This is the code I am trying to extract string list of action types using map operator
dataFooter?.actions?.map { it.type }?.toCollection()
I am not sure what should go in the toCollection method.
toCollection()is accepting another list where you want to add mapped elements withmap.toCollection()ortoList()in the first place?dataFooter?.actions?.map { it.type }already returns a list of strings.