java.util · java.base · since Java 1.2

Collection

declaration
public interface Collection<E> extends Iterable<E>

The root container contract: add/remove/contains/size/iterate. List, Set, and Queue refine it; algorithms accept it for maximum generality.

Key methods

boolean add(E) / remove(Object) / contains(Object)Core membership operations.
int size() / boolean isEmpty()Cardinality.
void clear()Remove every element.
Iterator<E> iterator()The cursor behind for-each; the only safe way to remove while iterating most collections.
boolean addAll(Collection<? extends E>)Bulk insert — union when the target starts empty.
boolean removeAll(Collection<?>)Bulk removal — set difference.
boolean retainAll(Collection<?>)Bulk removal — set intersection.
boolean containsAll(Collection<?>)Subset test.
boolean removeIf(Predicate<? super E>)Safe bulk removal — no CME.
Stream<E> stream() / parallelStream()Bridge into the Stream API.
Object[] toArray() / <T> T[] toArray(IntFunction<T[]>)Array snapshots — pass String[]::new.
<T> T[] toArray(T[] a)Legacy array overload — pass a correctly-sized array to skip a second allocation.