- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
How to sort an ArrayList in Java in descending order?
To sort the contents of an ArrayList in descending order
- Create an ArrayList.
- Sort the contents of the ArrayList using the sort() method of the Collections class.
- Then, reverse array list using the reverse() method of the Collections class.
Example:
import java.util.ArrayList; import java.util.Collections; public class ArrayListSample { public static void main(String[] args) { ArrayList<String> list = new ArrayList<String>(); list.add("JavaFx"); list.add("Java"); list.add("WebGL"); list.add("OpenCV"); Collections.sort(list); System.out.println(list); Collections.reverse(list); System.out.println(list); } }
Output:
[Java, JavaFx, OpenCV, WebGL] [WebGL, OpenCV, JavaFx, Java]
- Related Articles
- How to sort an ArrayList in Descending Order in Java
- Sort ArrayList in Descending order using Comparator with Java Collections
- How to sort an ArrayList in Ascending Order in Java
- How to sort an ArrayList in Java in ascending order?
- How to sort TreeSet in descending order in Java?
- How to sort List in descending order using Comparator in Java
- C# program to sort an array in descending order
- C program to sort an array in descending order
- How to perform descending order sort in MongoDB?
- Sort an array in descending order using C#
- How do you sort an array in C# in descending order?
- 8086 program to sort an integer array in descending order
- Sort MongoDB documents in descending order
- Python program to sort the elements of an array in descending order
- Golang Program To Sort The Elements Of An Array In Descending Order

Advertisements