Unit 4 Cycle 1 Day 26: Array vs ArrayList Comparison
Share
Array vs ArrayList Comparison
Section Mixed — Review: Collections
Key Concept
Arrays and ArrayList have different strengths. Arrays have fixed size, use bracket notation (arr[i]), store primitives directly, and have a length property. ArrayList has dynamic size, uses method calls (list.get(i)), only stores objects (autoboxing handles primitives), and has a size() method. Choose arrays when the size is known and fixed; choose ArrayList when the size may change. The AP exam tests your understanding of when each is appropriate.
Consider the following statements about arrays and ArrayLists.
Which statements are true?
Answer: (B) I, II, and III
I: TRUE. Array size is fixed. ArrayList resizes.
II: TRUE. Arrays hold int, double. ArrayList uses Integer, Double.
III: TRUE. Both start at index 0.
Why Not the Others?
(A) III is also true.
(C) II is also true.
(D) I is also true.
Common Mistake
ArrayList uses autoboxing for primitives. ArrayList is invalid. Use ArrayList.
AP Exam Tip
Array: fixed size, primitives ok, uses []. ArrayList: dynamic size, wrapper types only, uses get/set/add/remove.