Arrays

Learn about the array data structure, how it differs from lists and sets, and how you can use them in Kotlin.

Like lists and sets, arrays store multiple values in a linear data structure.

What is an Array? #

An array is a basic data structure in all programming languages. It stores multiple elements by placing them consecutively in memory. This structure is represented in the following illustration:

Array data structure. Elements are stored contiguously in memory and index starts at zero. [Source: https://beginnersbook.com/2018/10/data-structure-array/]
Array data structure. Elements are stored contiguously in memory and index starts at zero. [Source: https://beginnersbook.com/2018/10/data-structure-array/]

What’s the Difference Between Arrays, Lists, and Sets? #

Sets are easy to distinguish from both lists and arrays based on their special properties: no ordering and no duplicates.

To understand the difference between lists and arrays, we’ll have to look at the way their elements are stored and what implications this has for us as ...