Arrays
Arrays in Kotlin are not part of the language as they are in Java. In Kotlin, they are generic collection types. We’ll cover generics in later chapters. For now, we can describe them as types that have other types as a parameter. For example, this is how a Strings array is declared in Kotlin:
Array<String>
Kotlin also has specific array types for each of the Java primitive types. The reason for this is that only reference types can be generic type parameters and primitives would be automatically boxed (wrapped into reference types). There is the IntArray class, CharArray, LongArray and so on, for each primitive type.
The easiest way to create an array is to use the arrayOf function from the standard library, whether it is a primitive ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access