July 2018
Intermediate to advanced
400 pages
12h 14m
English
You access a value in a map using its key. For the patronGold map, you will use the string key to access the patron’s gold balance value.
Listing 11.4 Accessing individual gold balances (Tavern.kt)
...
fun main(args: Array<String>) {
...
println(uniquePatrons)
var orderCount = 0
while (orderCount <= 9) {
placeOrder(uniquePatrons.shuffled().first(),
menuList.shuffled().first())
orderCount++
}
println(patronGold)
println(patronGold["Eli"])
println(patronGold["Mordoc"])
println(patronGold["Sophie"])
}
Run Tavern.kt to print the balances for the three patrons you added to the map:
...
10.5
8.0
5.5
Note that the output includes only the values, not the keys.
As with other collections, Kotlin ...
Read now
Unlock full access