How to transform map values to a list in Kotlin

1 Answer

0 votes
fun main() {
    val mp = mapOf("Red" to 30, "Green" to 57, "Blue" to 86, "Yellow" to 102) 

    val doubledValuesList = mp.values.map { it * 2 }

    // Print each value separately
    doubledValuesList.forEach { println(it) }
}


 
  
/*
run:

60
114
172
204

*/

 



answered Aug 24, 2025 by avibootz

Related questions

1 answer 106 views
3 answers 178 views
2 answers 95 views
3 answers 111 views
1 answer 104 views
...