Collection Reverse in Java
Problem
Collections.reverse() is one of several static utility methods on the Collections class that operate on any List through the plain List interface, without depending on which concrete List implementation is behind it.
Given a List of strings, reverse the order of its elements in place.
Java Program
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class CollectionReverse {
public static void main(String[] args) {
List<String> queue = Arrays.asList("First", "Second", "Third", "Fourth");
Collections.reverse(queue); // reorders the list in place
System.out.println("Reversed: " + queue);
}
}Output
Core Logic
Calling Collections.reverse() on a plain List reference reorders it in place, working the same way regardless of which List implementation was actually passed in.
- 1
queueis declared and used purely as aList<String>, not tied to any specific implementation. - 2
Collections.reverse(queue)walks the list from both ends inward, swapping pairs of elements until the whole order is flipped. - 3The reversal happens in place — no new list is created, and the same
queuereference reflects the new order afterward. - 4This is the same call regardless of whether
queueis backed by an ArrayList, a LinkedList, or any other List implementation.
[First, Second, Third, Fourth] produces [Fourth, Third, Second, First], with the first and last elements swapped and the middle two swapped with each other.Key Point: This is part of a themed set of Collections utility methods — alongside min(), max(), frequency(), shuffle(), and swap() — that all operate through the List interface itself rather than any one concrete class's own methods.
Why: Collections.reverse() swaps pairs of elements working inward from both ends, touching each element exactly once, with no extra storage beyond the list itself.