Collection Types and Hierarchy
Learn about Kotlin collection types, their hierarchy, and mutability,
Introduction to collections
Collections are one of the most important concepts in programming. They are types that represent groups of elements. In Kotlin, the most important collection types are the following:
List
: This represents an ordered collection of elements. The same elements can occur multiple times. A list’s elements can be accessed by indexes (zero-based integer numbers that reflect elements’ positions). An example might be a list of songs in a queue: the order of the songs is important, and each song can appear in multiple places.Set
: This represents a collection of unique elements. It reflects the mathematical abstraction of a set—a group of objects without repetitions. Sets might not respect element order. However, the default set used by Kotlin does respect element order. An example might be a set of winning numbers in a lottery; they must be unique, but their order does not matter. ...