Choose the contract supported by each collection.
Read the lessons
- Java BitSet: distinguish logical length, capacity, and set-bit count
- Java BitSet nextSetBit: scan a bounded index range without walking gaps
- Java EnumSet complementOf: derive a default-deny capability set
- Java EnumSet: retain element type when a source collection is empty
- Java NavigableSet subSet: account for a live backed range
- Java PriorityBlockingQueue: add an admission limit to an unbounded priority queue
- Java CopyOnWriteArraySet: publish against a stable listener snapshot
- Java LinkedBlockingDeque: bound urgent and normal work in one queue
Common Mistakes
Do not confuse an initial allocation size with a resource limit.
