Concept Flow - Array creation and usage
Start
Create Array
Access Elements
Modify Elements
Use Array in Code
End
This flow shows how to create an array, access and modify its elements, then use it in your program.
fun main() { val numbers = arrayOf(10, 20, 30) println(numbers[1]) numbers[2] = 40 println(numbers.joinToString()) }
| Step | Action | Array State | Output |
|---|---|---|---|
| 1 | Create array with elements 10, 20, 30 | [10, 20, 30] | |
| 2 | Access element at index 1 | [10, 20, 30] | 20 |
| 3 | Modify element at index 2 to 40 | [10, 20, 40] | |
| 4 | Print all elements joined by comma | [10, 20, 40] | 10, 20, 40 |
| Variable | Start | After Step 1 | After Step 3 | Final |
|---|---|---|---|---|
| numbers | null | [10, 20, 30] | [10, 20, 40] | [10, 20, 40] |
Array creation: val arr = arrayOf(1, 2, 3) Access elements: arr[index], index starts at 0 Modify elements: arr[index] = newValue Use joinToString() to print array nicely Arrays hold fixed-size collections of items