在python中我可以使用
X = {A: "Apple", B: "Banana"}
print(x.value[0]) //Apple
在 kotlin 中我可以使用嗎?
println(x.value[0]) // Apple
uj5u.com熱心網友回復:
MapKotlin 中的 s 并不意味著通過索引訪問,所以你不能直接這樣做。他們確實按照添加的順序存盤條目(使用默認Map型別),這意味著您可以將它們轉換為 anIterable并獲取第一個專案,或者其他
val fruits = mapOf("A" to "Apple", "B" to "Banana")
// access values directly, use first() for readability
println(fruits.values.first())
// access elements, use an index, pull the value out of the entry
println(fruits.entries.elementAt(1).value)
// etc
這些屬性只是創建了條目、值等的排序Set,因此您只是創建了另一個包含現有物件視圖的容器。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/523751.html
標籤:科特林字典
