Collections.reverse(aList);

Example (Reference):

ArrayList aList = new ArrayList();
//Add elements to ArrayList object
aList.add("1");
aList.add("2");
aList.add("3");
aList.add("4");
aList.add("5");
Collections.reverse(aList);
System.out.println("After Reverse Order, ArrayList Contains : " + aList);
Answer from Shankar Agarwal on Stack Overflow
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java list โ€บ reverse an arraylist in java
Reverse an ArrayList in Java | Baeldung
April 3, 2025 - The Java standard library has provided the Collections.reverse method to reverse the order of the elements in the given List. This convenient method does in-place reversing, which will reverse the order in the original list it received.
Top answer
1 of 13
901
Collections.reverse(aList);

Example (Reference):

ArrayList aList = new ArrayList();
//Add elements to ArrayList object
aList.add("1");
aList.add("2");
aList.add("3");
aList.add("4");
aList.add("5");
Collections.reverse(aList);
System.out.println("After Reverse Order, ArrayList Contains : " + aList);
2 of 13
26

The trick here is defining "reverse". One can modify the list in place, create a copy in reverse order, or create a view in reversed order.

The simplest way, intuitively speaking, is Collections.reverse:

Collections.reverse(myList);

This method modifies the list in place. That is, Collections.reverse takes the list and overwrites its elements, leaving no unreversed copy behind. This is suitable for some use cases, but not for others; furthermore, it assumes the list is modifiable. If this is acceptable, we're good.


If not, one could create a copy in reverse order:

static <T> List<T> reverse(final List<T> list) {
    final List<T> result = new ArrayList<>(list);
    Collections.reverse(result);
    return result;
}

This approach works, but requires iterating over the list twice. The copy constructor (new ArrayList<>(list)) iterates over the list, and so does Collections.reverse. We can rewrite this method to iterate only once, if we're so inclined:

static <T> List<T> reverse(final List<T> list) {
    final int size = list.size();
    final int last = size - 1;

    // create a new list, with exactly enough initial capacity to hold the (reversed) list
    final List<T> result = new ArrayList<>(size);

    // iterate through the list in reverse order and append to the result
    for (int i = last; i >= 0; --i) {
        final T element = list.get(i);
        result.add(element);
    }

    // result now holds a reversed copy of the original list
    return result;
}

This is more efficient, but also more verbose.

Alternatively, we can rewrite the above to use Java 8's stream API, which some people find more concise and legible than the above:

static <T> List<T> reverse(final List<T> list) {
    final int last = list.size() - 1;
    return IntStream.rangeClosed(0, last) // a stream of all valid indexes into the list
        .map(i -> (last - i))             // reverse order
        .mapToObj(list::get)              // map each index to a list element
        .collect(Collectors.toList());    // wrap them up in a list
}

nb. that Collectors.toList() makes very few guarantees about the result list. If you want to ensure the result comes back as an ArrayList, use Collectors.toCollection(ArrayList::new) instead.


The third option is to create a view in reversed order. This is a more complicated solution, and worthy of further reading/its own question. Guava's Lists#reverse method is a viable starting point.

Choosing a "simplest" implementation is left as an exercise for the reader.

๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ reverse-an-arraylist-in-java
Reverse an ArrayList in Java using ListIterator - GeeksforGeeks
July 11, 2025 - To avoid that, same arraylist can be used for reversing. Logic: 1. Run the loop for n/2 times where 'n' is the number of elements in the arraylist. 2. In the first pass, Swap the first and nth element 3. In the second pass, Swap the second and ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ collections-reverse-method-in-java-with-examples
Collections.reverse() Method in Java with Examples - GeeksforGeeks
Note: It does not sort the elements, it simply reverses their current order. This class is present in java.util package so the syntax is as follows:
Published ย  July 23, 2025
๐ŸŒ
Blogger
javarevisited.blogspot.com โ€บ 2016 โ€บ 05 โ€บ how-to-reverse-arraylist-in-place-in-java.html
How to reverse an ArrayList in place in Java? Example [Solved]
July 10, 2024 - By the way, if you need to reverse an ArrayList then you should be using the Collections.reverse() method provided by the Java Collection framework. It's a generic method, so you can not only reverse an ArrayList but also Vector, LinkedList, CopyOnWriteArrayList, or any other List implementation.
๐ŸŒ
Medium
mominjahid.medium.com โ€บ arraylist-reverse-an-array-list-in-java-ed9a9505291
Arraylist & Reverse, an Array List in #Java | by Jahid Momin | Medium
June 3, 2022 - Java ArrayList class uses a dynamic Array for storing the elements. ... List<Integer> noList = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5, 6, 7)); Collections.reverse(noList);
Find elsewhere
๐ŸŒ
Java67
java67.com โ€บ 2015 โ€บ 01 โ€บ how-to-reverse-arraylist-in-java-with.html
How to reverse ArrayList in Java with Example | Java67
Here is my code example of reversing an ArrayList of Integer. You can see that we have added numbers on increasing order but after calling reverse() method, it prints them on decreasing order.
๐ŸŒ
w3resource
w3resource.com โ€บ java-exercises โ€บ collection โ€บ java-collection-exercise-11.php
Java - Reverse elements in an array list
May 21, 2025 - Write a Java program to reverse an ArrayList using Collections.reverse() and then print the reversed list.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ javaexamples โ€บ arrays_reverse.htm
How to reverse an array list in Java
Following example reverses an array list by using Collections.reverse(ArrayList)method. import java.util.ArrayList; import java.util.Collections; public class Main { public static void main(String[] args) { ArrayList arrayList = new ArrayList(); arrayList.add("A"); arrayList.add("B"); arrayList.add("C"); arrayList.add("D"); arrayList.add("E"); System.out.println("Before Reverse Order: " + arrayList); Collections.reverse(arrayList); System.out.println("After Reverse Order: " + arrayList); } }
๐ŸŒ
Apcomputersciencetutoring
apcomputersciencetutoring.com โ€บ reverse-arraylist
Reversing an ArrayList - AP Computer Science Exam Review
public static ArrayList<String> getReversed(ArrayList<String> list) { ArrayList<String> reversed = new ArrayList<String>(); for(String str : list) { reversed.add(0, str); } return reversed; }
๐ŸŒ
Blogger
javahungry.blogspot.com โ€บ 2017 โ€บ 09 โ€บ how-to-reverse-arraylist-in-java-with-Example.html
How to Reverse ArrayList in Java with Example | Java Hungry
... To reverse an ArrayList in java, one can use Collections class reverse method i.e Collections.reverse() method. Collections reverse method reverses the element of ArrayList in linear time i.e time complexity is O(n). Collections reverse method accepts a List type as an argument.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnprogramming โ€บ [java] need help reversing integers of a list into a separate arraylist.
r/learnprogramming on Reddit: [Java] Need help reversing integers of a List into a separate ArrayList.
December 9, 2015 -

This is a review question for my upcoming intro to programming exam and I need some help fixing my code. The question explicitly states to write a method that takes a List of integers and returns a new ArrayList in reverse order. It also says that we can assume we have methods prepend and append which add a new element to the beginning/end.

Here is my current code which gives me a NullPointerException

public static ArrayList<Integer> reverse(List<Integer> list){
	ArrayList<Integer> list2 = new ArrayList<Integer>();

	list.add(5);
	list.add(10);
	list.add(15);
	list.add(20);
	
	System.out.println(list);

	for(int i = 0, j = list.size()-1; i < j; i++){
		list2.add(i, list.remove(j));
	}
	
	return list2;
}
public static void main(String[] args){
	reverse(null);
}

Any help would be greatly appreciated. Thank you.

Edit: I am getting closer, 2 of the 4 objects are being reversed and displayed. More information is in the comments below.

Edit2: Thank you so much for all the help today guys, I understand this concept a lot better after reading through everyone's comments!

๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ reverse-order-of-all-elements-of-arraylist-with-java-collections
Reverse order of all elements of ArrayList with Java Collections
June 25, 2020 - In order to reverse order of all elements of ArrayList with Java Collections, we use the Collections.reverse() method.
๐ŸŒ
Java Concept Of The Day
javaconceptoftheday.com โ€บ home โ€บ how to reverse an arraylist in java?
How To Reverse An ArrayList In Java With Example?
August 25, 2016 - The given ArrayList can be reversed using Collections.reverse() method. Collections class is an utility class in java.util package which provides many useful methods to operate on Collection classes. Collections.reverse() method reverses the elements of the given ArrayList in linear time i.e ...
๐ŸŒ
FavTutor
favtutor.com โ€บ blogs โ€บ reverse-list-java
8 Ways to Reverse a List in Java | FavTutor
January 22, 2022 - When the loop terminates, the new list contains the reversed list. ... import java.util.*; public class FavTutor{ public static void main(String[] args) { List<String> clothes = new ArrayList<>(); clothes.add("T-shirt"); clothes.add("Pants"); clothes.add("Socks"); clothes.add("Shoes"); List<String> reverseClothes = new ArrayList<>(); ListIterator<String> listIterator = clothes.listIterator(clothes.size()); while(listIterator.hasPrevious()){ String elemenString = listIterator.previous(); reverseClothes.add(elemenString); } System.out.println("Before reversing:"); System.out.println(clothes); System.out.println("After reversing:"); System.out.println(reverseClothes); } }
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ How-to-reverse-an-ArrayList-in-Java
How to reverse an ArrayList in Java?
July 30, 2019 - The Collections class provides a method named reverse() this method accepts a list and reverses the order of elements in it. ... import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; public class Sample { public static void main(String[] ...
๐ŸŒ
Sololearn
sololearn.com โ€บ en โ€บ Discuss โ€บ 2124096 โ€บ reverse-arraylist
Reverse arraylist | Sololearn: Learn to code for FREE!
You can make a new list: Arraylist newlist = new Arraylist() for (int i = list.size() -1 ; i >= 0; i --){ newlist.add(list.get(i)); } But maybe there are better solutions
๐ŸŒ
Java Code Geeks
javacodegeeks.com โ€บ home โ€บ core java
Sorting ArrayList in Reverse or Descending Order in Java 8 - Java Code Geeks
March 3, 2021 - Collections.reverse(arraylist); โ€“> Next, reverse the sorted list. ... This program also produces the same output as in the section 2. Sorting list in reverse order is pretty easy from stream.sorted(Collections.reverseOrder()) in java 8 api.