Card 08/ 08
Recap: Lists
Two storage models, the operations each wins, growth by copying, and safe removal.
Lists come down to the six ideas below, each listed with the card that covers it.
| The idea | Where |
|---|---|
| Identical methods, opposite storage, opposite costs | ArrayList vs LinkedList: How Each Stores Its Elements |
| Positional reads are arithmetic on one and a walk on the other | ArrayList vs LinkedList Example: Reading by Position in a Loop |
| Inserting at the front shifts everything on one and changes two pointers on the other | ArrayList vs LinkedList Example: Inserting at the Front |
An ArrayList starts empty and grows by copying | How an ArrayList Grows When Its Array Is Full |
Use ArrayList unless the work is at the front or middle; then try ArrayDeque | Choosing Between ArrayList, LinkedList and ArrayDeque |
Remove with removeIf or the iterator, never through the list mid-loop | ConcurrentModificationException: Removing Inside a for-each Loop |
The interface tells you nothing about cost, on purpose; the operation your code does most decides.
- Java
- Java Collections
- Performance
← → move through sections and cards