2.4.5 Arrays vs Lists

Arrays vs Lists

The Wildcats use a fixed training grid for session-and-station assignments and a changing roster for players who arrive or leave. Choose storage that matches what can change.

Explore the idea
Compare the public behavior
Arrays and lists
Question Array List
How many dimensions? One or more One ordered sequence
Number of positions Fixed for that instance Can grow or shrink
Number of items or slots Length Count
First position Index 0 when nonempty Index 0 when nonempty
Add another position Create a different array Add or Insert an item
Store objects Stores references Stores references

A two-dimensional array preserves a rectangular row-and-column structure. A list is useful when the number of current entries varies. Neither choice automatically creates Player objects for its entries.

Keep length and capacity separate

Use an array for exactly four drill stations when every position has a stable meaning. Use a list for a roster that gains and loses entries. A fixed size does not make array elements read-only; stored values can still be replaced.

Predict and check