I have a list of custom objects. Below is the data class
:
data class ProductsResponse(
val id:String,
val ProductType:String
)
I have a below list:
var productList: List<ProductResponse>
我希望输出为:
var productNameList: List<String>
我想得到一份只有ProductType
人的名单,即Strings
人中的list
人
I know using a for loop and copying the ProductType
string to a new list will do the job. But I wanted to do it in a more shorter way using the power Kotlin
provides.
How can I convert the above custom object list
to a list
of Strings
in Kotlin way?