Java
ArrayList
Reverse
Programming
Data Structures

What is the Simplest Way to Reverse an ArrayList?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

The simplest way to reverse an ArrayList in Java is to use Collections.reverse(). It is built into the standard library, it works in place, and it is almost always clearer than writing a manual loop unless you specifically need a reversed copy instead of modifying the original list.

The standard answer: Collections.reverse

java
1import java.util.ArrayList;
2import java.util.Arrays;
3import java.util.Collections;
4
5public class Main {
6    public static void main(String[] args) {
7        ArrayList<Integer> numbers = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5));
8
9        Collections.reverse(numbers);
10
11        System.out.println(numbers);
12    }
13}

Output:

text
[5, 4, 3, 2, 1]

That is the simplest direct solution if you are okay with changing the original list.

Collections.reverse works in place

This detail matters. The method does not return a new reversed list. It modifies the existing one.

java
ArrayList<String> names = new ArrayList<>(Arrays.asList("Ada", "Lin", "Noah"));
Collections.reverse(names);
System.out.println(names);

If other code still expects the original ordering, reversing in place may be the wrong choice.

How to make a reversed copy instead

If you want to keep the original list unchanged, copy it first and then reverse the copy.

java
1import java.util.ArrayList;
2import java.util.Arrays;
3import java.util.Collections;
4
5ArrayList<String> original = new ArrayList<>(Arrays.asList("a", "b", "c"));
6ArrayList<String> reversed = new ArrayList<>(original);
7
8Collections.reverse(reversed);
9
10System.out.println(original); // [a, b, c]
11System.out.println(reversed); // [c, b, a]

That pattern is still simple, but it makes the mutability explicit.

Manual reversal is usually unnecessary

You can reverse an ArrayList manually with a loop, but it is rarely simpler than the library call.

java
1ArrayList<Integer> values = new ArrayList<>(Arrays.asList(1, 2, 3, 4));
2ArrayList<Integer> reversed = new ArrayList<>();
3
4for (int i = values.size() - 1; i >= 0; i--) {
5    reversed.add(values.get(i));
6}

This is fine when you specifically want to build a new reversed list yourself, but if the goal is just "reverse the list", Collections.reverse is more idiomatic.

What about streams

Java streams are powerful, but they are not the simplest way to reverse an ArrayList. Streams do not have a built-in reverse operation for lists, so a stream-based answer is usually more complicated than necessary.

That is a good example of a broader rule: use the most direct collection utility first, not the most fashionable API.

Performance and list type

Collections.reverse works on any List, not only ArrayList. It is a reasonable default for standard list reversal, and for ArrayList it performs well because indexed access is efficient.

If you are dealing with very large lists and care about allocations, the in-place approach is also attractive because it does not require building a second list.

Common Pitfalls

  • Expecting Collections.reverse to return a new list instead of modifying the existing one.
  • Reversing the original list when other code still depends on the original order.
  • Writing a manual loop when the standard library already does exactly what you need.
  • Overcomplicating the solution with streams for a simple collection operation.
  • Forgetting that the method works on List, so the variable does not have to be specifically typed as ArrayList.

Summary

  • The simplest way to reverse an ArrayList is Collections.reverse(list).
  • It reverses the list in place and does not create a new one.
  • If you need to preserve the original order, copy the list first and reverse the copy.
  • Manual loops work, but they are usually less clear than the built-in method.
  • For this task, the standard library solution is both the simplest and the most idiomatic.

Course illustration
Course illustration

All Rights Reserved.