Learn Java
import com.learnjava.datastructurescollections.CollectionsUtility;

The Collections Utility Class in Java

@Concept

Collections, from java.util (not to be confused with the Collection interface it operates on), is a class of static utility methods for working with lists and other collections as a whole: sort() orders a list in place, either by natural ordering or a supplied Comparator; reverse() flips a list's order; max() and min() find the largest or smallest element; and shuffle() randomizes element order.

These methods generally work directly on the collection passed in — sort() and reverse() both modify the original list in place rather than returning a new one. Several, like unmodifiableList(), wrap an existing collection to produce a read-only view that throws if anything tries to change it, useful for handing data out to code that shouldn't be able to modify the original.

@HowItWorks
1

sort()

Orders a list in place, using either the elements' natural ordering or an explicit Comparator passed as a second argument.

2

reverse()

Flips a list's element order in place.

3

max() and min()

Scan a collection to find its largest or smallest element, again respecting natural ordering or a supplied Comparator.

4

shuffle()

Randomizes a list's element order in place, useful for anything from card games to randomized testing.

5

unmodifiableList() and similar

Wrap an existing collection in a read-only view that throws an exception if any modification is attempted through it.

@Example
import java.util.ArrayList;
import java.util.Collections;
 
public class CollectionsUtilDemo {
public static void main(String[] args) {
ArrayList<Integer> numbers = new ArrayList<>();
numbers.add(3);
numbers.add(1);
numbers.add(2);
 
Collections.sort(numbers);
System.out.println("Sorted: " + numbers);
System.out.println("Max: " + Collections.max(numbers));
}
}
Output
Sorted: [1, 2, 3]
Max: 3
1Collections.sort(numbers) reorders the list in place, from its original [3, 1, 2] to [1, 2, 3].
2Printing numbers directly afterward shows that new, sorted order.
3Collections.max(numbers) scans the now-sorted list and correctly identifies 3 as the largest element.
4Both println calls run once each, giving two lines of output.
@UseCases
Sorting a list of custom objects by a specific field using a Comparator
Finding the highest or lowest value in a collection without writing a manual loop
Randomizing the order of a list, like shuffling a deck of cards
Handing out a read-only view of internal data with unmodifiableList so callers can't modify it

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in Java yourself — building beats watching.