Card 08/ 08
All 8 cards
RecapDifficulty: Advanced1 min
What a Set Refuses, and What a Queue Chooses
Five things this topic established, and where each one was.
| The thing | Where |
|---|---|
A set decides duplication with hashCode and equals on the element | A Collection That Decides What Counts as a Duplicate |
add returns whether the element was new, which saves a second lookup | Adding the Same Order Twice |
HashSet has no order, LinkedHashSet keeps insertion order, TreeSet sorts | Three Orderings, Three Costs |
| A priority queue is a heap, so only the front element is in order | Why Printing a PriorityQueue Does Not Show Poll Order |
Use ArrayDeque for both queues and stacks; Stack is a 1996 class | Why the Stack Class Still Exists |
Both halves of this topic are collections that make a decision for you. A set decides what is the same; a queue decides what is next. Choosing one means choosing whose decision you want.