val generatedArray = IntArray(10) { i -> i + 1 }
generatedArray
:
[1,2,3,4,5,6,7,8,9,10]
I want the array to start with 0
[0,1,2,3,4,5,6,7,8,9]
val generatedArray = IntArray(10) { i -> i + 1 }
generatedArray
:
[1,2,3,4,5,6,7,8,9,10]
I want the array to start with 0
[0,1,2,3,4,5,6,7,8,9]
2
Answers
First, if you start with zero and want to go to the Nth number, your array would have to be of size N + 1.
Second, this would be pretty simple –
This would generate the requested array –
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
just use i instead of i+1
val generatedArray = IntArray(10) { i -> i }