AP CSA Unit 4 Day 24: Arraylist Null Element

Unit 4, Data Collections • Cycle 2
Day 24 Advanced Practice • Harder Difficulty
Focus: ArrayList Null Element Hard ArrayList Null Element

Advanced Practice Question

Format: ArrayList Null Element

What is the output?
ArrayList list = new ArrayList<>();
list.add("A");
list.add(null);
list.add("B");

System.out.println(list.get(1));
System.out.println(list.size());
Difficulty: Hard  |  Topic: ArrayList Null Element  |  Cycle: 2 (Advanced)
Why This Answer?

ArrayLists can store null as a valid element. get(1) returns null. Size is 3 (three elements including null).

Common Mistake
Watch Out!

Thinking null elements don't count or cause errors.

AP Exam Strategy

ArrayLists can contain null. It counts as an element toward size().

Master This Topic

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

  • Understanding arraylist null element
  • 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.