Kotlin Program to Convert Map HashMap to List

Kotlin Program to Convert Map (HashMap) to List. We can convert key-value pairs into ArrayList or HashMap keys into ArrayList or HashMap values into ArrayList.

Kotlin Program to Convert Map HashMap to List

Source Code

import java.util.ArrayList
import java.util.HashMap

fun main(args: Array<String>) {

    val map = HashMap<Int, String>()
    map.put(1, "a")
    map.put(2, "b")
    map.put(3, "c")
    map.put(4, "d")
    map.put(5, "e")
    map.put(6, "f")

    val keyList = ArrayList(map.keys)
    val valueList = ArrayList(map.values)

    println("Key List: $keyList")
    println("Value List: $valueList")

}

Output