This flow shows how we create an array, access or change its elements by index, loop through it, and perform operations like searching or processing.
code_blocksExecution Sample
Java
int[] arr = {10, 20, 30};
arr[1] = 25;
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
This code creates an array, changes the second element, then prints all elements.
data_tableExecution Table
Step
Action
Index/Variable
Value/Condition
Array State
Output
1
Create array
-
-
[10, 20, 30]
-
2
Modify element
arr[1]
25
[10, 25, 30]
-
3
Start loop
i=0
0 < 3 is true
[10, 25, 30]
-
4
Print element
arr[0]
10
[10, 25, 30]
10
5
Increment i
i=1
-
[10, 25, 30]
10
6
Check loop
i=1
1 < 3 is true
[10, 25, 30]
10
7
Print element
arr[1]
25
[10, 25, 30]
10 25
8
Increment i
i=2
-
[10, 25, 30]
10 25
9
Check loop
i=2
2 < 3 is true
[10, 25, 30]
10 25
10
Print element
arr[2]
30
[10, 25, 30]
10 25 30
11
Increment i
i=3
-
[10, 25, 30]
10 25 30
12
Check loop
i=3
3 < 3 is false
[10, 25, 30]
10 25 30
13
End loop
-
-
[10, 25, 30]
10 25 30
💡 Loop ends when i reaches 3 and condition i < arr.length is false
search_insightsVariable Tracker
Variable
Start
After Step 2
After Step 5
After Step 8
After Step 11
Final
arr
[10, 20, 30]
[10, 25, 30]
[10, 25, 30]
[10, 25, 30]
[10, 25, 30]
[10, 25, 30]
i
-
-
1
2
3
3
keyKey Moments - 3 Insights
▶Why does the loop stop when i equals 3 and not when i is greater than 3?
▶What happens if we try to access arr[3]?
▶Why do we use arr.length in the loop condition?
psychologyVisual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the value of arr after step 2?
A[10, 20, 30]
B[25, 20, 30]
C[10, 25, 30]
D[10, 30, 25]
photo_cameraConcept Snapshot
Common array operations in Java:
- Create with int[] arr = {10, 20, 30};
- Access/modify elements by index: arr[1] = 25;
- Loop with for (int i = 0; i < arr.length; i++)
- Use arr.length to avoid out-of-bounds
- Arrays have fixed size after creation
contractFull Transcript
This lesson shows common array operations in Java. We start by creating an array with three numbers. Then we change the second element from 20 to 25. Next, we use a for loop to go through each element by index and print it. The loop runs while the index is less than the array length, which is 3. When the index reaches 3, the loop stops. We track the array and index values step by step. Key points include using arr.length to avoid errors and understanding when the loop ends. The quiz checks understanding of array state and loop behavior.