xxxxxxxxxx
data class mySubjectList(var name: String, var priority: String)
fun main() {
val mySubjectList: List<mySubjectList> = listOf(
mySubjectList("Java", "1"),
mySubjectList("Kotlin", "2"),
mySubjectList("C", "3")
)
// Creating a map and adding my own list of values in it.
val myMap: Map<String, String> = mySubjectList.associate {
Pair(it.priority, it.name)
}
println(myMap)
}
xxxxxxxxxx
fun main() {
val numbers = listOf("one", "two", "three", "four")
println(numbers.associateBy { it.first().toUpperCase() })
println(numbers.associateBy(keySelector = { it.first().toUpperCase() }, valueTransform = { it.length }))
}