- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Reverse order of all elements of ArrayList with Java Collections
In order to reverse order of all elements of ArrayList with Java Collections, we use the Collections.reverse() method.
Declaration −The java.util.Collections.reverse method is declared as follows −
public static void reverse(List<?> list)
Let us see a program to reverse order of all elements of ArrayList with Java Collections −
Example
import java.util.*; public class Example { public static void main (String[] args) { ArrayList<Integer> list = new ArrayList<Integer>(); list.add(1); list.add(2); list.add(7); list.add(8); list.add(3); list.add(9); System.out.println("Original list : " + list); Collections.reverse(list); // reversing the list System.out.println("Reversed list : " + list); } }
Output
Original list : [1, 2, 7, 8, 3, 9] Reversed list : [9, 3, 8, 7, 2, 1]
- Related Articles
- Replace All Elements Of ArrayList with with Java Collections
- Shuffle elements of ArrayList with Java Collections
- Swap elements of ArrayList with Java collections
- Copy Elements of One ArrayList to Another ArrayList with Java Collections Class
- Replace all occurrences of specified element of ArrayList with Java Collections
- Sort ArrayList in Descending order using Comparator with Java Collections
- Find maximum element of ArrayList with Java Collections
- Find minimum element of ArrayList with Java Collections
- Get Enumeration over ArrayList with Java Collections
- Perform Binary Search on ArrayList with Java Collections
- How to remove all elements of ArrayList in Java?
- Append all elements of other Collection to ArrayList in Java
- Reverse the order of the elements in the entire ArrayList or in the specified range in C#
- Insert all elements of other Collection to Specified Index of Java ArrayList
- Copy all elements of ArrayList to an Object Array in Java

Advertisements