Chapter 5Using Collections
We use collections of objects in every single application, whether it’s business, scientific, or game development. You can pretty much use any collection available in Java directly from within Kotlin. But, Kotlin also offers a few view interfaces over Java collections, which provide a pleasant and a safer coding experience.
For example, Kotlin provides Pair and Triple for a collection of two or three values, respectively. For larger fixed-size collections we can use an array, but for more flexibility we may use lists. We also often use sets and associative maps. Kotlin offers all of them.
Kotlin provides both a mutable and an immutable flavor for collection interfaces that serve as views to Java collections. If ...
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