How to initialize an array in Kotlin with values?

val numbers: IntArray = intArrayOf(10, 20, 30, 40, 50)

See Kotlin – Basic Types for details.

You can also provide an initializer function as a second parameter:

val numbers = IntArray(5) { 10 * (it + 1) }
// [10, 20, 30, 40, 50]

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)