Collections
Learn about the various types of collections that exist in Kotlin including lists, sets, and maps.
StartKey Concepts
Review core concepts you need to learn to master this subject
Immutable Lists
Mutable Lists
Accessing List Elements
The Size Property
List Operations
Immutable Sets
Mutable Sets
Accessing Set Elements
Immutable Lists
Immutable Lists
var programmingLanguages = listOf("C#", "Java", "Kotlin", "Ruby")
An immutable list represents a group of elements with read-only operations.
It can be declared with the term listOf
, followed by a pair of parentheses containing elements that are separated by commas.
Lists
Lesson 1 of 3
- 1In this section, we’re going to explore the various types of collections that exist in Kotlin. A collection is a group of elements that exist in a single structure. The first collection type we’l…
- 2In Kotlin, the terms “mutable” and “immutable” apply not only to variables but also to collections. Much like an immutable variable representing a read-only value, an immutable list contains item…
- 3A collection is of no use to us if we can’t access or work with its contents. In order to access the elements within a list, we must reference the element’s “index”. An index represents a numeric…
- 4Elements can be accessed from any list, but only with mutable lists can we change the contents of our list by adding, replacing, or removing elements. Previously we’ve only created immutable lists;…
- 5In Kotlin, the size property determines the number of elements within a collection. It is not only applicable to lists but also to other collections that we’ll be working with in the coming lessons…
- 6Every collection in Kotlin contains a series of built-in functions that allow us to perform certain operations in order to retrieve information about the collection or manipulate its values. A fu…
What you'll create
Portfolio projects that showcase your new skills
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory