otakusenpai
02/20/2020, 1:30 PMjava.lang.ArrayIndexOutOfBoundsException: Index 6 out of bounds for length 6
In this code
fun getMarketMap(stats: MarketStats): Map<String,MarketResponse> {
var map = mutableMapOf<String,MarketResponse>()
for(i in 0 until (stats.marketPrice.size)) {
println("$i th: ${locations[i]}")
map[locations[i]] = stats.marketPrice[i]
}
return map
}
and if possible any way to improve the codedeactivateduser
02/20/2020, 1:33 PMjmillner_
02/20/2020, 1:33 PMKristoffer Andersen
02/20/2020, 1:33 PMjmillner_
02/20/2020, 1:33 PMjmillner_
02/20/2020, 1:33 PMotakusenpai
02/20/2020, 1:33 PMval locations = listOf("Caerleon","Lymhurst","Martlock","Bridgewatch",
"FortSterling","Thetford")
otakusenpai
02/20/2020, 1:34 PMdeactivateduser
02/20/2020, 1:34 PMotakusenpai
02/20/2020, 1:34 PMotakusenpai
02/20/2020, 1:37 PMAleksa Boškov
02/20/2020, 1:49 PMstats.marketPrice
.mapIndexed { index, element ->
println(whatever you need)
locations[index] to element
}
.toMap()
Aleksa Boškov
02/20/2020, 1:49 PMzip
functionAleksa Boškov
02/20/2020, 1:51 PMIterable
that Kotlin provides over iterating in loops