kotlin string array code example

Example 1: how to declare string array in kotlin

//String[] in Java equivalent Array<String> in Kotlin 
//eg.
var array1 : Array<String?> = emptyArray()
var array2: Array<String?> = arrayOfNulls(4)
var array3: Array<String> = arrayOf("Mashroom", "Kitkat", "Oreo", "Lolipop")

Example 2: kotlin array

val a: Array<Double> = arrayOf(3.0, 4.5, 8.0, 19.0)

Example 3: kotlin size of array

arr = arrayOf(10, 20, 30, 40, 50)

// Use the size attribute
println(arr.size)