W3Schools
w3schools.com › java › java_sort_list.asp
Java Sort a List - List Sorting
Sort a Java list alphabetically or numerically with Collections.sort().
W3Schools
w3schools.com › java › ref_arraylist_sort.asp
Java ArrayList sort() Method
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Practice Problems Java Server Java Syllabus Java Study Plan Java Interview Q&A · ❮ ArrayList Methods · Sort a list in alphabetical order: import java.util.ArrayList; public class Main { public static void main(String[] args) { ArrayList<String> cars = new ArrayList<String>(); cars.add("Volvo"); cars.add("BMW"); cars.add("Ford"); cars.add("Mazda"); cars.sort(null); System.out.println(cars); } } Try it Yourself » ·
16:02
How To Sort A List Using Java 8 different ways - YouTube
01:07
Sort list of string using java 8 streams - YouTube
20:14
CP-1.010 Java Tutorial - Sorting an ArrayList - YouTube
05:53
Java Collection List Sort using Comparator Interface - YouTube
06:48
Java 8 Tutorial 05 :- How to sort a List in Java 8 using Comparator ...
15:58
Java 8 Stream - Sort List (ArrayList) in Ascending and Descending ...
W3Schools
w3schools.com › java › ref_linkedlist_sort.asp
Java LinkedList sort() Method
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Practice Problems Java Server Java Syllabus Java Study Plan Java Interview Q&A · ❮ LinkedList Methods · Sort a list in alphabetical order: import java.util.LinkedList; public class Main { public static void main(String[] args) { LinkedList<String> cars = new LinkedList<String>(); cars.add("Volvo"); cars.add("BMW"); cars.add("Ford"); cars.add("Mazda"); cars.sort(null); System.out.println(cars); } } Try it Yourself » ·
Javaprogramto
javaprogramto.com › 2020 › 04 › java-collection-sort-custom-sorting.html
Collections sort() in Java - List Custom Sort Example
April 11, 2020 - List of integer prime numbers sorting program. package com.java.w3schools.blog.collections.sorting; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; /** * * Collections.sort() example to sort List of Strngs.
W3Schools
w3schools.com › java › exercise.asp
Exercise: JAVA List Sorting
List Sorting3 q · HashSet4 q · HashMap4 q · Iterator4 q · Wrapper Classes4 q · Regular Expressions5 q · Threads3 q · Lambda Expressions4 q · Advanced Sorting3 q by w3schools.com · Next Question » · Try Again · You have already completed these exercises! Do you want to take them again? Yes No · × · Close the exercise · You completed the JAVA List Sorting Exercises from W3Schools.com ·
GeeksforGeeks
geeksforgeeks.org › java › collections-sort-java-examples
Collections.sort() in Java with Examples - GeeksforGeeks
Sorts elements based on natural ordering or custom Comparator ... import java.util.*; public class Collectionsorting { public static void main(String[] args) { // Create a list of strings ArrayList<String> al = new ArrayList<String>(); al.add("Geeks For Geeks"); al.add("Friends"); al.add("Dear"); al.add("Is"); al.add("Superb"); /* Collections.sort method is sorting the elements of ArrayList in ascending order.
Published: April 30, 2026
Javatpoint
javatpoint.com › how-to-sort-a-list-in-java
How to Sort a List in Java - Javatpoint
How to Sort a List in Java with oops, string, exceptions, multithreading, collections, jdbc, rmi, fundamentals, programs, swing, javafx, io streams, networking, sockets, classes, objects etc,
Java Code Geeks
examples.javacodegeeks.com › home › java development › core java › util › list
Sorted List Java Example - Java Code Geeks
July 22, 2020 - Create a Java class called SimpleSortExample with the following source code. ... Firstly I filled the list with random values, using (int) (Math.random() * 100) to get integers between 0 and 100.
W3schools
w3schools.dev › java › java_arraylist.asp
Java ArrayList - W3Schools
Another useful class in the java.util package is the Collections class, which include the sort() method for sorting lists alphabetically or numerically:
BeginnersBook
beginnersbook.com › 2013 › 12 › how-to-sort-arraylist-in-java
How to sort ArrayList in Java
//Sorting in Ascending order ArrayList<Integer> numbers = new ArrayList<>(List.of(4, 1, 3, 2)); Collections.sort(numbers); // Sort the ArrayList in ascending order System.out.println(numbers); // Output: [1, 2, 3, 4] //Sorting in Descending order ArrayList<Integer> numbers = new ArrayList<...
Java Code Geeks
examples.javacodegeeks.com › home › java development › core java
Sorting Java ArrayList in Ascending and Descending Order - Java Code Geeks
October 23, 2023 - In the above example, we start by creating an ArrayList of 5 Strings. We then use the Collections.sort() method to sort the list in ascending order.
Top answer 1 of 16
696
Collections.sort(testList);
Collections.reverse(testList);
That will do what you want. Remember to import Collections though!
Here is the documentation for Collections.
2 of 16
184
Descending:
Collections.sort(mArrayList, new Comparator<CustomData>() {
@Override
public int compare(CustomData lhs, CustomData rhs) {
// -1 - less than, 1 - greater than, 0 - equal, all inversed for descending
return lhs.customInt > rhs.customInt ? -1 : (lhs.customInt < rhs.customInt) ? 1 : 0;
}
});
CodeJava
codejava.net › java-core › collections › sorting-list-collections-examples
Java Sort List Collections Examples
This would be useful if we need to sort a list of custom objects which we cannot modify its class; or if we don’t want to rely on the natural ordering of the elements. The following code is example of a comparator that compares two employees based on their ages: package net.codejava.collections; import java.util.Comparator; /** * This comparator compares two employees by their ages.
Programiz
programiz.com › java-programming › library › arraylist › sort
Java ArrayList sort()
import java.util.ArrayList; import ... System.out.println("Sorted ArrayList: " + languages); } } ... In the above example, we have used the sort() method to sort the arraylist named languages....