I can initialize an array in Kotlin like this:
val mArr = Array<Int>(5) {0}
and I'll have the following array [0,0,0,0,0]
The thing is, I need to initialise an array and put the values of another array into it. i.e:
initialArray = [1, 4, 5 ,-2, 7]
val offset = 5
And should get mArr = [6, 9, 10, 3, 12]
Is there a way to set the value of each mArr[i]
based on each initialArray[i]
?
Something like
val mArr = Array<Int>(initialArray.size) { offset + initialArray[index]}
Without wrapping it in a for loop