Instruction 2

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Set

A set stores only unique values. Remember that a List will happily store duplicates? In the Set, every duplicate is removed by the Set object. For this reason, the order of elements isn’t defined, as some items may be removed if duplicated. The Set interface represents sets in Kotlin.

Read-only Sets

A Set may also be mutable or immutable, like a List. To initialize an immutable set, use setOf:

Mutable Sets

Here’s an example of the mutableSetOf method, which initializes a mutable Set:

Map

A Map differs from the List and Set in that they store key-value pairs instead of single items. A key in a Map is unique. If a new key duplicates an existing key, the existing key value is updated with the new value.

Collection Elements

The items in a collection are usually of the same type or subtype, but they may also be completely different types.

See forum comments
Download course materials from Github
Previous: Instruction 1 Next: Instruction 3