Difference between ByteArray and Array in kotlin

Due to Java’s limitations, Kotlin has 9 array types: Array<…> for arrays of references (in the JVM sense) and 8 specialized array types, i.e. IntArray, ByteArray etc.

https://kotlinlang.org/docs/reference/java-interop.html#java-arrays

The main reason for this distinction is performance: if we didn’t specialize arrays it’d lead to a lot of boxing/unboxing and make arrays slow. This would be unacceptable because the only reason one might want to prefer arrays over collections is performance.

Leave a Comment