beginnerFree
Pick the Right Collection
A quick decision guide

Start with what you need - the right collection makes your code simpler and faster.
Watch
The narrated version of this skribble — tap play for the full-size video.
0:00 / 2:09
Deep dive
The Big Picture
Choosing the right collection is a performance decision.
- Ask: ordering? uniqueness? key-value? thread-safety?
ArrayList: default for listsHashSet: fast uniqueness checksHashMap: fast key-value lookups
Different implementations optimize different operations.
How It Works
Each collection trades off speed, order, and uniqueness.
ArrayList: get(i) O(1), append amortized O(1), front/middle insert/remove O(n)HashSet/HashMap: O(1) average, no orderTreeSet/TreeMap: O(log n), sortedLinkedHashMap: insertion order + O(1)ArrayDeque: O(1) for queue/stack patterns
In the Java Landscape
Decision tree for common cases:
- Ordered + fast access?
ArrayList - Unique + fast check?
HashSet - Sorted + unique?
TreeSet - Key-value, fastest lookup?
HashMap - Key-value + sorted keys?
TreeMap - FIFO queue?
ArrayDeque
Pitfalls and Best Practices
- Profile before optimizing -
ArrayListis usually fine - Don't default to
LinkedList- slower than expected - Use
Setforcontains()checks, notList - Size collections when you know capacity
- Thread safety? Use
java.util.concurrenttypes



