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.

What a strong answer looks like

A strong Unit 5 answer says which positions are visited, whether anything was changed, and whether another name can see that change.

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.

Study move

Make an array of five numbers and print the first and last.

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.

Study move

Try to double every value with a for-each loop and explain why it fails.

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.

Study move

Write a method that changes an array and confirm the caller sees it.

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.

Study move

Remove every negative value both forwards and backwards and compare the results.

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.

Mastery checklist

  • State the valid positions of an array.
  • Choose the loop that lets you change values.
  • Explain how a method can change your array.
  • Remove items from a list without skipping any.

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