Skip to main content
← Intro to CS (Java) Study Guide

Unit 5 · Heavy

Collections of Values

Holding many values under one name. Arrays are a fixed size; lists grow and shrink. This is also the first place two names can point at the same data, which surprises everyone the first time.

Topics in this unit

1

Arrays

Practice this topic →

Know

An array holds a fixed number of values, reached by position from zero. Its size is decided when it is made and cannot change.

Apply

State the size and the valid positions before writing a loop.

Watch out

Mixing up the size property on arrays with the length operation on text.

2

Going Through an Array

Practice this topic →

Know

A counting loop can both read and change items. The simpler for-each loop reads a copy and cannot replace anything.

Apply

Use the counting loop whenever you need to change values.

Watch out

Assigning to the for-each variable and expecting the array to change. It does not.

3

Changing and Sharing

Practice this topic →

Know

Assigning to a position changes the stored value. Passing an array to a method passes the array itself, so the method can change your data.

Apply

Trace the contents after each change, and note when two names refer to one array.

Watch out

Assuming a method got a copy. It did not, and its changes are permanent.

4

Lists That Grow

Practice this topic →

Know

A list can grow and shrink. Removing an item slides everything after it down, which is why removing inside a loop needs care.

Apply

When removing while looping, either go backwards or do not advance after a removal.

Watch out

Removing forwards with a normal step, which silently skips the item after each removal.

Emphasized in this unit

Connections and techniques that receive extra attention in this unit.

  • • Knowing whether code reads or changes
  • • Understanding that two names can share one array
  • • Handling removal during a loop carefully

Varies by course

Related topics some schools attach to this unit and others leave out. Covered on request rather than assumed.

  • 2D arrays. Introduced here in some sections and left to AP CSA in others.
  • Wrapper types. Covered lightly at this level.

Check yourself

  • • Why does a for-each loop not let you replace values?
  • • What does it mean for two names to share one array?
  • • Why does removing forwards skip items?

Modeling drill

Write code that removes every score below 40 from a list and explain why your loop does not skip any.

ArrayPositionfor-eachSharingListRemovalShift

Need help with this topic?

Work through questions with a tutor and get help with the steps you find difficult.

Get help with this topic