Home » Java Collections reverse() Method with Examples

Java Collections reverse() Method with Examples

by Online Tutorials Library

Java Collections reverse() Method

The reverse() method of Java Collections class is used to reverse the order of the elements in the specified list.

Syntax

Following is the declaration of reverse() method:

Parameter

Parameter Description Required/Optional
list It is the list whose elements are to be reversed. Required

Returns

The reverse() method does not return anything.

Exceptions

NA

Compatibility Version

Java 1.2 and above

Example 1

Test it Now

Output:

Original List:- [Java, PHP, Python, COBOL]  Modified List:- [COBOL, Python, PHP, Java]  

Example 2

Test it Now

Output:

Original List:- [1, 2, 3, 4]  Modified List:- [4, 3, 2, 1]  

Example 3

Test it Now

Output:

Original Array : [10, -20, 30, -40, 50]  Modified Array : [50, -40, 30, -20, 10]  

You may also like