Java ProgramsCollectionsCollection Reverse

Collection Reverse in Java

beginner·  Collections  ·  Collections Utility

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.

Input
[First, Second, Third, Fourth]
Output
Reversed: [Fourth, Third, Second, First]

Java Program

Java
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

Reversed: [Fourth, Third, Second, First]

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.

How It Works
  1. 1queue is declared and used purely as a List&lt;String&gt;, not tied to any specific implementation.
  2. 2Collections.reverse(queue) walks the list from both ends inward, swapping pairs of elements until the whole order is flipped.
  3. 3The reversal happens in place — no new list is created, and the same queue reference reflects the new order afterward.
  4. 4This is the same call regardless of whether queue is backed by an ArrayList, a LinkedList, or any other List implementation.
Reversing [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.

Complexity
Time Complexity: O(n)Space Complexity: O(1)

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.

Key Concepts

Collections.reverse()List interfacein-place mutation

Related Programs