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 117 views
3 answers 188 views
2 answers 98 views
3 answers 117 views
1 answer 121 views
...