how to do for loop for each map key only in kotlin?

Viewed 937

I see that to iterate in each key value pair is:

map.forEach { key, value -> println("$key = $value") }

How do I iterate and get all the values for each key - Something like...

map.forEach { key -> println("$key") }

thanks

1 Answers

There's myMap.keys and myMap.values if you just want to iterate over one of those. And myMap.entries if you want the actual Entry object, where your forEach variable would need to be { (key, value) -> } instead (i.e. a single variable with two components)

Related