list map by index and value kotlin

To list map by index and value in Kotlin, you can use the mapIndexed function, which provides the index and value of each element in the collection. Here's an example:

val list = listOf("apple", "banana", "orange")

val indexedMap = list.mapIndexed { index, value -> index to value }.toMap()

println(indexedMap)

In this example, the mapIndexed function iterates over the elements of the list and provides the index and value of each element. The toMap() function then converts the list of pairs into a map, where the index is the key and the value is the value in the map.