<aside> 📦

L2.2 — Collections and Iterators covers the limitations of arrays, introduces ArrayList as a dynamic alternative (declaration, insertion, access, removal), explains generics for type safety, autoboxing/unboxing for primitives, and the Iterator pattern for decoupled collection traversal.

</aside>

📋 At a Glance


1. Problems with Arrays

Arrays have four key limitations:

  1. Fixed size — once created, the size cannot change
  2. Painful insertion — adding new elements is difficult if you don't know how many exist already
  3. Index-only access — you must use numeric indices to interact with elements
  4. ArrayIndexOutOfBoundsException — accessing a nonexistent index causes a runtime error