Card 08/ 08
Recap: Sets and Queues
How sets decide sameness, the three set orders, heaps, and the replacement for Stack.
Sets and queues come down to the five ideas below, each listed with the card that covers it.
| The idea | Where |
|---|---|
A HashSet decides duplication with hashCode and equals on the element | Sets: How a HashSet Decides What Counts as a Duplicate |
add returns whether the element was new, saving a second lookup | HashSet Example: Adding the Same Order Twice |
HashSet has no order, LinkedHashSet keeps insertion order, TreeSet sorts | HashSet vs LinkedHashSet vs TreeSet |
| A priority queue is a heap, so only the front element is in order | PriorityQueue Iteration Order: Printing Does Not Show Poll Order |
Use ArrayDeque for queues and stacks; Stack is a Java 1.0 class | Stack vs ArrayDeque: Why the Stack Class Should Not Be Used |
A set decides what is the same, and a queue decides what is next. Choosing one means choosing whose decision you want.
← → move through sections and cards