In Java, java.util.Collections (since Java 1.2) is a utility class: a toolbox of static methods that work on collections you already have. It is final, its only constructor is private, and every member is static, so you never write new Collections(). You just call Collections.sort(list).
Most methods throw NullPointerException for a null collection, and UnsupportedOperationException when they try to change a collection that cannot be changed (such as one from emptyList() or Arrays.asList when it would need to grow).
Syntax
Java Syntax
Import the class, then call its static methods on the class name:
The unmodifiable*, synchronized*, and checked* methods do not copy anything. They return a wrapper (a view) that forwards every call to your original collection and adds one rule on top. Changes to the original show through the view.
A view is not an immutable copy. For lists that nobody can ever change, use Collections.emptyList(), singletonList(), or (Java 9+) List.of(...) and List.copyOf(...) (Java 10+).
Code
Java Examples
Example 1 — Sort, Search, and Find the Extremes
Put exam scores in order, look one up with a binary search, read the highest and lowest, then sort from high to low.
Java
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class CollectionsHubScores {
public static void main(String[] args) {
List<Integer> scores = new ArrayList<>(Arrays.asList(72, 95, 64, 88));
Collections.sort(scores);
System.out.println("Sorted: " + scores);
System.out.println("88 is at index " + Collections.binarySearch(scores, 88));
System.out.println("Best " + Collections.max(scores) + ", lowest " + Collections.min(scores));
Collections.sort(scores, Collections.reverseOrder());
System.out.println("High to low: " + scores);
}
}
Output
Sorted: [64, 72, 88, 95]
88 is at index 2
Best 95, lowest 64
High to low: [95, 88, 72, 64]
How It Works
A changeable list. The four scores are copied into an ArrayList, because Collections.sort rearranges the list it is given.
Ascending first.Collections.sort(scores) uses the natural order of Integer, so the list becomes 64, 72, 88, 95.
Binary search on sorted data. Now that the list is in order, binarySearch can halve the search range each step and reports 88 at index 2.
Extremes without sorting.max and min scan the collection once and return 95 and 64.
A reversed comparator.Collections.reverseOrder() flips natural order, so the second sort puts the highest score first.
Example 2 — Hand Out a Read-Only View
A class keeps its own team list but lets other code look at it only through an unmodifiable view.
Java
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class CollectionsHubView {
public static void main(String[] args) {
List<String> team = new ArrayList<>();
team.add("Ana");
team.add("Ben");
List<String> readOnly = Collections.unmodifiableList(team);
try {
readOnly.add("Eve");
} catch (UnsupportedOperationException e) {
System.out.println("Blocked: " + e.getClass().getSimpleName());
}
team.add("Cy");
System.out.println("View now shows " + readOnly + " (size " + readOnly.size() + ")");
}
}
Output
Blocked: UnsupportedOperationException
View now shows [Ana, Ben, Cy] (size 3)
How It Works
The owner's list.team is an ordinary ArrayList holding Ana and Ben.
Wrap, do not copy.unmodifiableList(team) returns a thin wrapper object that forwards reads to team.
Writes are refused. Calling add on the wrapper throws UnsupportedOperationException, so outside code cannot change the team.
Still live. The owner adds Cy to the original list, and the wrapper immediately reports three names, because it never had its own copy.
Example 3 — Build a List, Count Values, and Replace Them
Start with three repeated votes, add more in one call, count each answer, then rename one answer everywhere.
java.util.Collections is a utility class with only static methods. They work on collections you already have: sorting and searching lists, finding the maximum or minimum, counting elements, and creating empty, single-element, read-only, synchronized, or type-checked collections.
Collection is an interface: the root type for List, Set, and Queue. Collections is a final helper class with static methods that accept those collections. You implement or use Collection; you call methods on Collections.
No. The Collections Framework is the whole family of interfaces and classes (Collection, List, Set, Map, ArrayList, HashMap, and so on). The Collections class is one small part of it: a toolbox of static helper methods.
No. It returns a read-only view of the same list. You cannot change the list through the view, but changes made to the original list are visible through it. Copy the list first, or use List.copyOf in Java 10+, if you need a snapshot.
No. Its only constructor is private, and the class is final. All its methods and constants (such as EMPTY_LIST) are static.