Collections are a general concept for most programming languages. A collection usually consists of several objects of the same type, and the objects in a collection are called elements or items.
Kotlin Standard Library provides a comprehensive set of tools for managing archives. The following collection types are relevant to the code:
Kotlin offers the following types of collections:
Calling an immutable collection or a collection interface provides read-only methods, i.e., once a collection has been created, we cannot change it because there is no way to change the created object.
| Collection Types | Methods of Immutable Collection |
|---|---|
| List | listOf() listOf |
| Map | mapOf() |
| Set | setOf() |
It provides methods for reading and writing interchangeable collections.
| Collection Types | Methods of mutable Collection |
|---|---|
| List | ArrayList arrayListOf() mutableListOf() |
| Map | HashMap hashMapOf() mutableMapOf() |
| Set | hashSetOf() mutableSetOf() |
Note: Altering a mutable collection doesn't require it to be a var.
|
|