AP CSA Unit 4 Day 28: Arraylist Equality

Unit 4, Data Collections • Cycle 2
Day 28 Advanced Practice • Harder Difficulty
Focus: ArrayList Equality Hard ArrayList Equality

Advanced Practice Question

Format: ArrayList Equality

What is the output?
ArrayList a = new ArrayList<>();
a.add(1);
a.add(2);

ArrayList b = new ArrayList<>();
b.add(1);
b.add(2);

System.out.println(a == b);
System.out.println(a.equals(b));
Difficulty: Hard  |  Topic: ArrayList Equality  |  Cycle: 2 (Advanced)
Why This Answer?

== compares references (different objects = false). equals() for ArrayList compares contents element-by-element (same contents = true).

Common Mistake
Watch Out!

Thinking == checks contents for ArrayLists.

AP Exam Strategy

For ArrayLists: == checks references, equals() checks contents.

Master This Topic

This Cycle 2 HARD question tests arraylist equality. Review Unit 4 concepts to build mastery of data collections.

  • Understanding arraylist equality
  • Tracing code execution accurately
  • Avoiding common pitfalls
View Unit 4 Study Guide

Ready for More Challenges?

Cycle 2 questions prepare you for the hardest AP CSA exam questions.

Study Games Practice FRQs
Back to blog

Leave a comment

Please note, comments need to be approved before they are published.