I have a list as follows:
val numbers = listOf("one", "two", "three", "four")
I want to create a map such that each index goes to each value of the list.
1 to "one", 2 to "two", ..
I want the result to be a
Map<Int, String>
One of the ways could be:
numbers.mapIndexed { index: Int, s: String -> index + 1 to s }.toMap()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With