Wrapping Up
Kotlin extends Java collections and at the same time brings along improved compile-time safety via read-only views. Use the read-only views when working with functional style, writing concurrent code, or when programming asynchronously.
Kotlin’s Pair and Triple are useful to create finite small-sized collections. For a larger fixed-sized collection, reach for the Array class. However, for flexibility to grow the collection, choose between List or Set. When working with collections, you have to choose methods, like listOf() to get a read-only view of the JDK collection, or methods like mutableListOf(), to get a read-write view. To work with associative maps, use the Kotlin view interfaces to interact with Java’s Map implementations. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access