- 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 ascending order?
You can sort an ArrayList using the sort() method of the Collections class this method accepts a list object as a parameter and sorts the contents of it in ascending order.
Example:
import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; 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"); Set<String> set = new LinkedHashSet<String>(list); Collections.sort(list); System.out.println(list); } }
Output:
[Java, JavaFx, OpenCV, WebGL]
- Related Articles
- How to sort an ArrayList in Ascending Order in Java
- How to sort an ArrayList in Descending Order in Java
- How to sort an ArrayList in Java in descending order?
- Java Program to Sort Array list in an Ascending Order
- How to sort Java array elements in ascending order?
- C program to sort an array in an ascending order
- How to perform ascending order sort in MongoDB?
- Java program to sort words of sentence in ascending order
- How do you sort an array in C# in ascending order?
- 8086 program to sort an integer array in ascending order
- C program to sort an array of ten elements in an ascending order
- Sort Elements in an ArrayList in Java
- Python program to sort the elements of an array in ascending order
- How can we sort MySQL output in ascending order?
- Sort index in ascending order – Python Pandas

Advertisements