This article explores different ways to convert a map to an array of key/value pairs in Kotlin.

1. Using toTypedArray() function

The easiest solution to get an array of key/value pairs in Kotlin is by calling the toList() function on the map first, followed by the toTypedArray() function.

Download Code

2. Using entries properties

The Map’s entries properties return a set of all key/value pairs in the map. To get an array of key/value pairs, you can use the map() function, as shown below:

Download Code

3. Using keys properties

The Map’s keys properties return a set of all keys present on the map. To get an array of key/value pairs, you can use the map() function, as shown below:

Download Code

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