Card 08/ 08
All 8 cards
RecapDifficulty: Advanced1 min
One Interface, Two Cost Profiles
Six things this topic established, and where each one was.
| The thing | Where |
|---|---|
| Identical methods, opposite storage, opposite costs | Two Lists With the Same Methods and Opposite Costs |
| Positional reads are arithmetic on one and a walk on the other | Getting the Five-Hundredth Element |
| Inserting at the front shifts everything on one and changes two pointers on the other | Inserting at the Front of Each |
An ArrayList starts at zero capacity and grows by copying | What an ArrayList Does |
Use ArrayList unless the work is genuinely at the front or middle | Which List Your Access Pattern Asks For |
Remove with removeIf or the iterator, never through the list mid-loop | Why Removing Inside a for-each Throws |
The one worth carrying: the interface tells you nothing about cost, on purpose. What decides between these two is which operation your code does most, which is a question about your code and not about the library.
- Java
- Java Collections
- Performance