August 2017
Intermediate to advanced
440 pages
10h
English
In Kotlin, arrays are represented by the Array class. To create an array in Kotlin, we can use a number of Kotlin standard library functions. The simplest one is arrayOf():
val array = arrayOf(1,2,3) // inferred type Array<Int>
By default, this function will create an array of boxed Int. If we want to have an array containing Short or Long, then we have to specify the array type explicitly:
val array2: Array<Short> = arrayOf(1,2,3)
val array3: Array<Long> = arrayOf(1,2,3)
As previously mentioned, using boxed representations may decrease application performance. That's why Kotlin has a few specialized classes representing arrays of primitive types to reduce boxing memory overhead: ShortArray, IntArray, LongArray, and so on. These ...
Read now
Unlock full access