One would use `intArrayOf()` if one wants to initi...
# getting-started
s
One would use
intArrayOf()
if one wants to initialize an
IntArray
with specific and different values otherwise one can simply use
IntArray()
. Is that correct?
Copy code
* 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)
e
also
Copy code
IntArray(3) { it + 1 } // same result as intArrayOf(1, 2, 3)
useful to initialize an array with a constant or pattern