Lesson 4.4: Store and Process a List
A list stores several related values in a specific order. Each position has an index, which is a number used to find one item.
The Blockly list menu calls the first position item 1. Java uses index 0 for the first item, so a Java array with three items has valid indexes 0, 1, and 2. The data stays in the same order even though the displayed position starts differently.
Store a list in a variable when several parts of the program need it. A loop can process each item instead of using a separate command for every position.
Lists can contain numbers, text, or Boolean values. Keeping related items the same type usually makes later operations clearer.
Guided practice
Create the list [4, 7, 2] and store it in scores. Print item 1, then item 3. Predict both outputs.
Use a for each item in list loop to print every score. Count how many times the loop body runs. Then add each item to a variable named total and print the final total after the loop.
Java arrays and lists use the same main ideas: ordered items, indexes, length, and repeated processing.
Loading the block workspace...
Ready to move on?
Only mark complete if you genuinely understand the material. Your progress will be saved in this browser.
Stuck on this lesson?
Ask about anything on this page. It can see which lesson you have open and which part you are reading.