Example 1 — Reverse a List and Watch the Middle
Reverse five numbers, check where the middle one ends up, then reverse again.
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class CollectionsReverseMirror {
public static void main(String[] args) {
List<Integer> nums = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5));
System.out.println("Before: " + nums + ", 3 at index " + nums.indexOf(3));
Collections.reverse(nums);
System.out.println("After: " + nums + ", 3 at index " + nums.indexOf(3));
Collections.reverse(nums);
System.out.println("Twice: " + nums);
}
} How It Works
- Pairs swap. Index 0 swaps with index 4 and index 1 with index 3, so 1 and 5 trade places, then 2 and 4.
- Middle stays. With five elements, index 2 has no partner, so the 3 is still at index 2 after reversing.
- Undo. A second
reversemirrors the list back to its starting order.

