Flavors of Collections
We'll cover the following...
In Java, we’re used to different types of collections: List
, Set
, Map
, and so on. We can use them in Kotlin as well. The mutable collection interfaces of Java are split into two interfaces in Kotlin: an immutable read-only interface and a mutable read-write interface. Kotlin also provides a number of convenience methods on collections in addition to those from the JDK.
Types of collections in Kotlin
When you’re ready to iterate over the elements in any of these collections, Kotlin makes that task easier and much more fluent than in Java. At a high level, you may use the following collections in Kotlin:
-
Pair
—a tuple of two values. -
Triple
—a tuple of three values. -
Array
—indexed fixed-sized collection of objects and primitives. -
List
—ordered collection of objects. -
Set
—unordered collection of objects. -
Map
—associative dictionary or map of keys and values.
Since Java already offers a wide range of collections in the ...