You can reverse ArrayList in Java by using
reverse() method of
java.util.Collections class. This is one of the many utility method provided by Collections class e.g.
sort() method for sorting ArrayList. The
Collections.reverse() method also accepts a List, so you not only can reverse ArrayList but also any other implementation of List interface e.g.
LinkedList or
Vector or even a custom implementation. This method has time complexity of O(n) i.e. it runs on linear time, because it uses ListIterator of given list. It reverse the order of element in specified list. By the way you cannot reverse an ArrayList using this method if the specified ArrayList or it's ListIterator doesn't support
set() operation. It switches between two algorithm depending upon the size of List or if
List implements
RandomAccess interface e.g. ArrayList. If number of elements in List is less than
REVERSE_THRESHOLD, which is equal to 18 then it uses for loop for swapping elements otherwise it uses list iterator. If you want to learn more about
how reverse() method of Collections works, you can see it's code from JDK itself or in the next section. By the way, this is a
typesafe generic method and you can use it to reverse Integer, String, Float or any kind of List in Java.