Reader small image

You're reading from  Kotlin Design Patterns and Best Practices - Third Edition

Product typeBook
Published inApr 2024
PublisherPackt
ISBN-139781805127765
Edition3rd Edition
Right arrow
Author (1)
Alexey Soshin
Alexey Soshin
author image
Alexey Soshin

Alexey Soshin is a software architect with 18 years of experience in the industry. He started exploring Kotlin when Kotlin was still in beta, and since then has been a big enthusiast of the language. He's a conference speaker, published writer, and the author of a video course titled Pragmatic System Design
Read more about Alexey Soshin

Right arrow

Reviewing Kotlin data structures

There are three important groups of data structures we should become familiar with in Kotlin: lists, sets, and maps. We’ll provide a brief overview of each here, and then delve into topics related to data structures, including mutability and tuples, in more detail in Chapter 5, Introducing Functional Programming.

Lists

A list in Kotlin represents an ordered collection of elements of the same type. To declare a list, we utilize the listOf() function instead of calling the constructor of a specific list implementation. This function provides a convenient way to create a list and initialize it with elements:

val hobbits = listOf("Frodo", "Sam", "Pippin", "Merry")

It is important to note that we didn’t explicitly specify the type of the list. This is because type inference can be employed when constructing collections in Kotlin, similar to initializing variables.

If you prefer to...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Kotlin Design Patterns and Best Practices - Third Edition
Published in: Apr 2024Publisher: PacktISBN-13: 9781805127765

Author (1)

author image
Alexey Soshin

Alexey Soshin is a software architect with 18 years of experience in the industry. He started exploring Kotlin when Kotlin was still in beta, and since then has been a big enthusiast of the language. He's a conference speaker, published writer, and the author of a video course titled Pragmatic System Design
Read more about Alexey Soshin