Arrays of Objects and Primitives

The Array<T> class represents an array of values in Kotlin. Use arrays only when low-level optimization is desired; otherwise, use other data structures like List, which we’ll see later in this chapter.

Creating an array in Kotlin

The easiest way to create an array is using the arrayOf() top-level function. Once you create an array, you may access the elements using the index [] operator.

To create an array of Strings, for example, pass the desired values to the arrayOf() function:

Get hands-on with 1200+ tech skills courses.