This post will discuss how to reverse a list in Java by modifying the list in-place. That means that the conversion should occur without using any auxiliary list by overwriting the existing elements of the specified list.

Assume that the specified list is modifiable. For immutable lists, an UnsupportedOperationException should be thrown.

1. Using Collections.reverse() method

The idea is to use the Collections.reverse() method to reverse the order of the elements in the specified list.

Download  Run Code

Output:

[BLACK, BLUE, RED]

2. Using List.add() with List.remove() method

Another approach to in-place reverse a list is to reorder the elements present in the list using a for-loop, which removes an element from the end of the list and insert it into the very beginning, one at a time.

Download  Run Code

Output:

[BLACK, BLUE, RED]

3. Using Recursion

We can also use recursion to reverse a list in-place, as demonstrated below:

Download  Run Code

Output:

[BLACK, BLUE, RED]

That’s all about reversing a List in Java.