java.util · java.base · since Java 1.2
Set
public interface Set<E> extends Collection<E>A collection with no duplicates, as judged by equals (or compareTo in sorted sets). add() returning false is the built-in "seen before" test.
Key methods
boolean add(E e) | false if an equal element exists — dedup in one call. |
boolean remove(Object o) | Removes the equal element, if present. |
boolean contains(Object o) | Equals-based membership test — the reason to reach for a Set at all. |
boolean retainAll(Collection<?> c) | In-place intersection with another collection. |
static <E> Set<E> of(E...) | Immutable set literal (throws on duplicate args!). |
static <E> Set<E> copyOf(Collection<E>) | Immutable defensive copy. |