Lists
Lists hold an ordered collection of values and allow duplicate values. They are the most prevalent collection type due to their relative ease of use and overall simplicity compared to other data structures. Because of their ordering properties in particular, lists are a great tool for storing information like a queue of tavern patrons or the list of items on the tavern menu.
In Tavern.kt, open your tavern for business by adding a list of patrons using the listOf function. listOf returns a read-only list populated with the elements you provide for the argument. Create your list with three patron names:
Listing 9.3 Creating a list of patrons (Tavern.kt
)
private const val TAVERN_MASTER = "Taernyl" private const val ...
Get Kotlin Programming: The Big Nerd Ranch Guide, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.