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
09:32
How to SORT an ArrayList in Java | Java Comparator & Stream & ...
02:49
Sort ArrayList in Ascending order | Java Program - YouTube
13:25
How to sort a collection in java | Collections.sort() | sorting ...
12:03
Sort ArrayList of Objects - YouTube
03:46
Java Tutorial 23 - Looping and Sorting an ArrayList - YouTube
06:36
Sorting Collections in Java - Mastering the Collections.sort() ...
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); } } }
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.
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.
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.
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.