The java.util.Collections class is a utility class of static methods that operate on or return collections. It sorts, searches, shuffles, reverses and finds extremes in lists, builds unmodifiable and synchronized wrappers, and creates empty or single-element collections. You never instantiate it; you call Collections.sort(list) and similar methods directly.
It is part of the Java Collections Framework, and it should not be confused with the Collection interface, which is the root type for lists and sets.
sort, reverse, shuffle, swap, rotate, fill, binarySearch.max, min, frequency, disjoint.unmodifiableList, unmodifiableSet, unmodifiableMap, synchronizedList and similar.emptyList, singletonList, nCopies.reverseOrder.The constructor is private, so all methods are static. Most algorithms take a List, because they need positional access.
Two details matter here. binarySearch requires the list to be sorted in the same order first; on an unsorted list the result is undefined. It returns a negative value, -(insertionPoint) - 1, when the element is missing. Also, Collections.sort modifies the list, so it fails with UnsupportedOperationException on lists created by List.of(...), which is why the example copies into an ArrayList. Since Java 8 you can also call names.sort(null) or names.sort(Comparator.naturalOrder()).
Pass your own Random (or RandomGenerator in recent Java) when you need reproducible results.
Collections.unmodifiableList(list) returns a read-only view. It is a view, not a copy: changes to the original list are visible through it. For a real immutable snapshot, use List.copyOf(list) (Java 10 and later) or List.of(...).
Collections.synchronizedList(new ArrayList<>()) wraps a list so that each method call is synchronized on the wrapper. Iteration is still not atomic, so you must lock manually while iterating:
For concurrent workloads, prefer classes from java.util.concurrent, such as ConcurrentHashMap and CopyOnWriteArrayList, over synchronized wrappers.
| Method | Result |
|---|---|
Collections.emptyList() | Immutable empty list, shared instance |
Collections.singletonList(x) | Immutable list with one element |
Collections.nCopies(3, "ab") | Immutable list of three copies |
Collections.addAll(c, a, b, c) | Adds several elements to a collection |
For new code, List.of, Set.of and Map.of are usually clearer than singletonList, and they reject null elements.
Collection is an interface, the root of lists and sets. Collections is a final utility class full of static helper methods.
No. It needs a List. For sorted sets use TreeSet, or copy the elements into a list first.
No, it is a read-only view of the original list. Use List.copyOf for an independent immutable copy.
Single operations are, but iteration and compound actions need external synchronization.
Collections provides static helpers for sorting, searching, shuffling, wrapping and creating collections. Remember that binarySearch needs sorted input, unmodifiable wrappers are views, and synchronized wrappers need manual locking for iteration. For modern code, combine it with List.of, List.copyOf and the java.util.concurrent classes.