Java ArrayLists Are Not Magical
summary
Explains how java.util.ArrayList uses an Object[] backing array that grows by a 1.5× factor so resizes are geometric and individual add operations are amortized O(1). Shows that calling ensureCapacity or addAll avoids repeated resizes (benchmarks about 5× faster than naive per-element adds), that remove(index) shifts the tail and nulls the freed slot for GC, that removeIf is much faster than repeated remove calls, and notes CopyOnWriteArrayList copies the array on each write and Project Valhalla aims to provide faster primitive-style collections.
AI-written summary · about
chapters (14)
- 0:00Introduction
- 0:22Why study ArrayLists
- 1:04ArrayList internals
- 2:30Add element cost
- 4:37Add methods compared
- 5:21Removing elements
- 6:46Remove methods benchmark
- 7:09Java list comparison
- 8:39Mutable set pitfalls
- 9:21List traversal risks
- 10:50CopyOnWriteArrayList concurrency
- 11:53Modifying during traversal
- 12:14Valhalla future performance
- 12:59Q&A








