🌐
GeeksforGeeks
geeksforgeeks.org › java › collections-sort-java-examples
Collections.sort() in Java with Examples - GeeksforGeeks
Collections.sort(List<T> list); Sorts the list in ascending order (natural order) Elements must implement Comparable · Example: Sorting an ArrayList in ascending order · JAVA ·
Published: April 30, 2026
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-collections-sort
Java Collections sort() | DigitalOcean
Technical tutorials, Q&A, events — This is an inclusive place where developers can find or lend support and discover new ways to contribute to the community.
🌐
Medium
medium.com › @AlexanderObregon › sorting-lists-in-java-using-collections-sort-14b150ac8682
Sorting Lists in Java Using Collections.sort | Medium
June 4, 2025 - The mechanics behind sorting with Collections.sort() are tied to how Java decides what should come before what. Whether you're using built-in ordering or passing in a comparator, every comparison shapes how the list gets rearranged. The actual sorting is handled by TimSort, which picks up on patterns in your data to sort faster when it can.
🌐
W3Schools
w3schools.com › java › java_sort_list.asp
Java Sort a List - List Sorting
Sort an ArrayList of Strings alphabetically in ascending order: import java.util.ArrayList; import java.util.Collections; // Import the Collections class 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"); Collections.sort(cars); // Sort cars for (String i : cars) { System.out.println(i); } } }
🌐
BeginnersBook
beginnersbook.com › 2013 › 12 › java-arraylist-of-object-sort-example-comparable-and-comparator
Java ArrayList of Object Sort Example (Comparable And Comparator)
Now we can very well call Collections.sort on ArrayList · import java.util.*; public class ArrayListSorting { public static void main(String args[]){ ArrayList<Student> arraylist = new ArrayList<Student>(); arraylist.add(new Student(223, "Chaitanya", 26)); arraylist.add(new Student(245, "Rahul", 24)); arraylist.add(new Student(209, "Ajeet", 32)); Collections.sort(arraylist); for(Student str: arraylist){ System.out.println(str); } } }
🌐
Career Karma
careerkarma.com › blog › java › learn to sort arraylist in java
Learn to Sort ArrayList in Java: A Step-by-Step Guide | Career Karma
December 1, 2023 - Collections.reverse() is used to sort the elements in an ArrayList, but in reverse order. Using examples, this article will discuss sorting an ArrayList in Java.
🌐
Spring Framework Guru
springframework.guru › home › how to sort java collections
How To Sort Java Collections - Spring Framework Guru
October 22, 2024 - Collections.sort(): This is designed primarily for sorting objects within collections like ArrayList, LinkedList, and other data structures implementing the List interface.
🌐
CodeGym
codegym.cc › java blog › java collections › java collections sort()
Java Collections sort()
October 11, 2023 - Collections.sort(colors); on an ArrayList of Colors rather than just Strings, it would work because Collections understands how to compare Color objects. If you do not want to make your object implement Comparable<Object>, you can alternatively write a comparator for your class, and pass that into the 2-parameter Collections.sort() method.
🌐
How to do in Java
howtodoinjava.com › home › java sorting › java collections.sort(): natural order, comparator, stability
Java Collections.sort(): Natural Order, Comparator, Stability
July 21, 2018 - The classes ArrayList and the fixed-size list from Arrays.asList() override sort() and sort their own array in place, without the copy. In both cases, the algorithm is TimSort, a stable merge sort that takes O(n log n) comparisons on random ...
Find elsewhere
🌐
Vultr
docs.vultr.com › java › standard library › java › util › arraylist › sort()
Java ArrayList sort() - Order Elements
November 15, 2024 - The output will display the sorted list: [1, 5, 9]. Understand that Comparator provides a way to define the custom order. Implement a comparator to sort the list in descending order. Use the Collections.sort() with the comparator.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-program-to-sort-an-arraylist
Java Program to Sort an ArrayList - GeeksforGeeks
July 23, 2025 - An ArrayList of Wrapper class object is nothing but an ArrayList of objects like String, Integers, etc. An ArrayList can be sorted in two ways ascending and descending order. The collection class provides two methods for sorting ArrayList.
🌐
TutorialsPoint
tutorialspoint.com › collections-sort-in-java-with-examples
Java Collections sort() Method
December 27, 2023 - The Java Collections sort(List<T>) method is used to sort the specified list into ascending order, according to the natural ordering of its element.
🌐
Baeldung
baeldung.com › home › java › java collections › difference between arrays.sort() and collections.sort()
Difference Between Arrays.sort() and Collections.sort() | Baeldung
March 7, 2025 - Unlike Arrays.sort(), which is limited to arrays, Collections.sort() can sort more dynamic data structures like ArrayList, LinkedList, and other classes that implement the List interface.
🌐
Scaler
scaler.com › home › topics › how to sort arraylist in java?
How to Sort ArrayList in Java? - Scaler Topics
October 14, 2022 - Usually, the elements are stored in an unsorted manner. To arrange the data in a sorted manner we use different methods. An ArrayList can be sorted in two ways ascending or descending order. Mainly the collections class provides two methods to sort an ArrayList in Java in ascending or descending ...
🌐
Codecademy
codecademy.com › docs › java › collections › .sort()
Java | Collections | .sort() | Codecademy
July 18, 2022 - import java.util.*; // This sorts by natural ordering Collections.sort(myList); // This sorts by a Comparator Collections.sort(myList, myComparator); Both methods sort myList. The first sorts myList using the natural ordering of the elements. The second uses myComparator to order the elements. The following example creates an ArrayList and then uses Collections.sort() to reorder its elements: import java.util.*; public class Main { public static void main(String[] args) { ArrayList<String> food = new ArrayList<String>(); food.add("Cabbage"); food.add("Pizza"); food.add("Sausage"); food.add("Potatoes"); food.add("Salad"); System.out.println(food); Collections.sort(food); System.out.println(food); } } Copy to clipboard ·
🌐
Interview Kickstart
interviewkickstart.com › home › blogs › learn › collections sort in java
Collections Sort in Java | Interview Kickstart
September 25, 2024 - List<Student> listOfStudents = new ArrayList<>(); listOfStudents.add(new Student(“John”, 70, 50, 80)); listOfStudents.add(new Student(“Tom”, 40, 50, 60)); listOfStudents.add(new Student(“Harry”, 90, 50, 40)); listOfStudents.add(new Student(“Max”, 80, 90, 40)); listOfStudents.add(new Student(“Philip”, 60, 70, 90)); // sort using lambda supported by java 8 and above · Collections.sort(listOfStudents, new Comparator<Student>() { public int compare(Student student1, Student student2) { return student1.totalMarks() – student2.totalMarks(); } }); for(Student student: listOfStudents) { System.out.println(student.toString()); } } } Output: We can also use lambda expressions here.
🌐
iO Flood
ioflood.com › blog › sort-arraylist-java
How to Sort ArrayList in Java: A Step-by-Step Guide
February 27, 2024 - In this example, we create an ArrayList named ‘numbers’ and populate it with the integers 5, 3, 8, and 1. We then use the Collections.sort() method to sort the ArrayList. The output is the sorted ArrayList: [1, 3, 5, 8]. This is just a basic ...
🌐
BeginnersBook
beginnersbook.com › 2013 › 12 › how-to-sort-arraylist-in-java
How to sort ArrayList in Java
To sort an ArrayList in descending order, we need to pass Collection.reverseOrder() as a second parameter in the Collections.sort() method as shown below. The same way, we can sort an ArrayList of integer type in descending order as well. import java.util.*; public class JavaExample{ public ...
🌐
freeCodeCamp
freecodecamp.org › news › how-to-sort-a-list-in-java
How to Sort a List in Java – Java List Sorting Example
January 24, 2023 - Here is an example of how to use the Collections.sort() method to sort a list of integers: import java.util.Collections; import java.util.List; import java.util.ArrayList; public class Main { public static void main(String[] args) { List<Integer> numbers = new ArrayList<Integer>(); numbers.add(3); numbers.add(1); numbers.add(4); numbers.add(2); Collections.sort(numbers); System.out.println("Sorted List: " + numbers); } } The above code creates a list of integers, adds four numbers to it, sorts the list, and then prints the sorted list to the console.
🌐
JanBask Training
janbasktraining.com › community › java › how-to-sort-a-listarraylist
How to sort a List/ArrayList? | JanBask Training Community
May 21, 2025 - Whether you want to sort numbers, strings, or custom objects, Java has you covered. ... The simplest way to sort a List or ArrayList is by using the static method Collections.sort().