A collection contains several objects of a similar type, and these objects in the collection are called elements or items. Collection can help to store, retrieve, manipulate, and aggregate data.
Types of Collections:
Immutable collection
This type of collection support read-only functionalities. One cannot modify its elements.
Methods include:
- List – listOf() and listOf<T>()
- Set – setOf()
- Map – mapOf()
Mutable Collection
It supports both read and write functionality.
Methods include
- List – mutableListOf(),arrayListOf() and ArrayList
- Set – mutableSetOf(), hashSetOf()
- Map – mutableMapOf(), hashMapOf() and HashMap