Sudhir Singh Khanger
12/29/2020, 5:35 AMintArrayOf()
if one wants to initialize an IntArray
with specific and different values otherwise one can simply use IntArray()
. Is that correct?
* These two are the same
val arr: IntArray = intArrayOf(0, 0, 0)
val arr = IntArray(3)
* IntArray with different values
val arr = IntArray(3)
arr[0] = 1
arr[0] = 2
arr[0] = 3
vs
val arr: IntArray = intArrayOf(1, 2, 3)
ephemient
12/29/2020, 5:41 AMIntArray(3) { it + 1 } // same result as intArrayOf(1, 2, 3)
useful to initialize an array with a constant or pattern