how to get some field list in object list in kotlin
fun main(args:Array<String>){
println("Hello World")
val list = listOf(member("hong",10), member("kil", 10))
}
data class member(var name:String, var age:Int)
Above code, I want to get single field list in above code such as name
{"hong", "kil"}
You want to get list with only name field? If so, then use map
(https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/map.html)
val names = list.map { it.name }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With