How to Reverse ArrayList in Java ?

In this tutorial, we will learn how to Reverse ArrayList in Java.

ArrayList in Java is a resizable-array implementation of the List interface. ArrayList in Java implements all optional list operations, and permits all elements, including null. In addition to implementing the List interface, this class provides methods to manipulate the size of the array that is used internally to store the list.

The ArrayList class extends AbstractList and implements the List interface. ArrayList supports dynamic arrays that can grow as needed. Standard Java arrays are of a fixed length. After arrays are created, they cannot grow or shrink, which means that you must know in advance how many elements an array will hold.

If we want to reverse an ArrayList, then Collections class in Java provides a method reverse() to reverse an ArrayList. The syntax of reverse() method is:

Syntax of reverse() method:

this method reverses the order of the elements in the specified list.

list – the list whose elements are to be reversed.

UnsupportedOperationException – if the specified list or its list-iterator does not support the set operation.



Related posts

Leave a Comment