Home > front end >  How to make a list of primitive values based on the list of objects - Kotlin?
How to make a list of primitive values based on the list of objects - Kotlin?

Time:10-25

I got list of objects. Each object has its values. data class User(val name: String, val age: Int) so I have a list of 15 Users each of them got name and age. How to make a separate list with only ages? Like convert listOfUsers to listOfAges?

CodePudding user response:

Transform the collection using map:

val listOfAges = listOfUsers.map { it.age }
  • Related