This article explores different ways to convert a map to a list in Kotlin.

1. Using toList() function

In Kotlin, you can easily get a list contained in this map by calling the toList() function on the map instance.

Download Code

 
Output:

(A, 65)
(B, 66)
(C, 67)

 
If you just need the list of keys or list of values, you can do like:

Download Code

2. Using entries properties

The Map’s entries properties return a set of all key/value pairs in the map. To convert it into a list, you can use the map() function.

Download Code

 
Output:

(A, 65)
(B, 66)
(C, 67)

3. Using keys properties

The Map’s keys properties return a set of all keys present on the map. To get the List, you can use the map() function.

Download Code

 
Output:

(A, 65)
(B, 66)
(C, 67)

That’s all about converting a map to a list in Kotlin.