

The Kotlin Standard Library provides implementations for basic collection types: sets, lists, and maps. The collection interfaces and related functions are located in the llections package. So, the Kotlin Standard Library offers generic interfaces, classes, and functions for creating, populating, and managing collections of any type. In other words, you add a String to a list of Strings the same way as you would do with Ints or a user-defined class. Kotlin lets you manipulate collections independently of the exact type of objects stored in them. Maps are useful for storing logical connections between objects, for example, an employee's ID and their position. Keys are unique, and each of them maps to exactly one value. Map (or dictionary) is a set of key-value pairs. For example, the numbers on lottery tickets form a set: they are unique, and their order is not important.

Generally, the order of set elements has no significance. It reflects the mathematical abstraction of set: a group of objects without repetitions. An example of a list is a telephone number: it's a group of digits, their order is important, and they can repeat. Elements can occur more than once in a list. List is an ordered collection with access to elements by indices – integer numbers that reflect their position. The following collection types are relevant for Kotlin: For example, all the students in a department form a collection that can be used to calculate their average age.

Objects in a collection are called elements or items. The Kotlin Standard Library provides a comprehensive set of tools for managing collections – groups of a variable number of items (possibly zero) that are significant to the problem being solved and are commonly operated on.Ĭollections are a common concept for most programming languages, so if you're familiar with, for example, Java or Python collections, you can skip this introduction and proceed to the detailed sections.Ī collection usually contains a number of objects (this number may also be zero) of the same type.
