Arrays are much asic than the collection types. They don’t support resizing, are always mutable, and overwrite values in the array instead of making room for them.
fun displayAges(ages: IntArray){ ... }
val ages = intArrayOf(18,21,16,30)
displayAges(ages)
// Converting listOf
val ages = listOf(18,21,16,30)
displayAges(ages.toIntArray())| Array type | Creation Function |
|---|---|
| IntArray | intArrayOf |
| DoubleArray | doubleArrayOf |
| LongArray | longArrayOf |
| ShortArray | shortArrayOf |
| ByteArray | byteArrayOf |
| FloatArray | floatArrayOf |
| BooleanArray | booleanArrayOf |
| Array | arratOf |
💡
Arraycompiles to a primitive array that holds any reference type.
