How do I create a map from 2 arrays?

You can zip together the arrays to get a list of pairs (List<Pair<String, Int>>), and then use toMap to get your map.

Like this:

val keys = arrayOf("butter", "milk", "apples")
val values = arrayOf(5, 10, 42)

val map: Map<String, Int> = 
             keys.zip(values) // Gives you [("butter", 5), ("milk", 10), ("apples", 42)]
                 .toMap()     // This is an extension function on Iterable<Pair<K, V>>

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)