java.util · java.base · since Java 1.4
LinkedHashSet
public class LinkedHashSet<E> extends HashSet<E>
implements SequencedSet<E>, Cloneable, SerializableHashSet plus a linked list through the entries: O(1) operations with predictable insertion-order iteration.
- The deterministic-order upgrade when tests or users see the iteration
Key methods
LinkedHashSet(int initialCapacity) | Presize like HashSet; insertion order is preserved regardless of capacity. |
static <E> LinkedHashSet<E> newLinkedHashSet(int numElements) | Correctly presized factory (Java 19+). |