Use this method Collections.sort(List,Comparator) . Implement a Comparator and pass it to Collections.sort().

class RecipeCompare implements Comparator<Recipe> {

    @Override
    public int compare(Recipe o1, Recipe o2) {
        // write comparison logic here like below , it's just a sample
        return o1.getID().compareTo(o2.getID());
    }
}

Then use the Comparator as

Collections.sort(recipes,new RecipeCompare());
Answer from AllTooSir on Stack Overflow
🌐
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
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › Collections.html
Collections (Java Platform SE 8 )
July 21, 2026 - These algorithms may, but are not required to, throw this exception if an invocation would have no effect on the collection. For example, invoking the sort method on an unmodifiable list that is already sorted may or may not throw UnsupportedOperationException. This class is a member of the Java Collections Framework.
🌐
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 - Java provides several tools for sorting, but one of the most commonly used is Collections.sort(). It works with lists of numbers, strings, or even custom objects when you provide it with a way to compare them.
🌐
Baeldung
baeldung.com › home › java › java collections › sorting in java
Sorting in Java | Baeldung
February 3, 2026 - Note that we can use Collections.sort() in a similar fashion to sort List and Set of Objects in Natural or Custom order as described above for Arrays. Start with Java 8, we can use Lambdas to implement the Comparator Functional Interface.
🌐
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 - In both cases, the algorithm is TimSort, a stable merge sort that takes O(n log n) comparisons on random data and about n comparisons on data that is already almost sorted. // does not compile: JDK source of Collections (excerpt) public static <T extends Comparable<? super T>> void sort(List<T> list) { list.sort(null); } public static <T> void sort(List<T> list, Comparator<? super T> c) { list.sort(c); }
🌐
Spring Framework Guru
springframework.guru › home › how to sort java collections
How To Sort Java Collections - Spring Framework Guru
October 22, 2024 - To help us sort objects, Collections.sort() can utilize a Comparator to allow us to specify custom sort criteria. You can see for the output, we are using Java’s versatile printf() method.
Find elsewhere
🌐
W3Schools
w3schools.com › java › java_sort_list.asp
Java Sort a List - List Sorting
Another useful class in the java.util package is the Collections class, which include the sort() method for sorting lists alphabetically or numerically.
🌐
TutorialsPoint
tutorialspoint.com › java › util › collections_sort_comparable.htm
Java Collections sort() Method
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.
🌐
Interview Kickstart
interviewkickstart.com › home › blogs › learn › collections sort in java
Collections Sort in Java | Interview Kickstart
September 25, 2024 - Collections sort is a method of Java Collections class used to sort a list, which implements the List interface. All the elements in the list must be mutually comparable. If a list consists of string elements, then it will be sorted in alphabetical ...
🌐
Medium
medium.com › @reetesh043 › collection-sort-vs-arrays-sort-in-java-1528f83223c3
Collection.sort() vs Arrays.sort() in Java | by Reetesh Kumar
February 21, 2024 - This method ensures stability in sorting, meaning that equal elements maintain their relative order after sorting, making it a reliable choice for various sorting tasks in Java applications. Under the hood, Collection.sort() uses a modified version of the merge sort algorithm.
🌐
CodeGym
codegym.cc › java blog › java collections › java collections sort()
Java Collections sort()
October 11, 2023 - Thankfully, Collections.sort()is overwritten with an optional 2nd parameter, which allows you to do just this: sort(List l, Comparator c) But what’s a comparator? Well, a comparator is simply a function that compares two inputs and returns a number representing which input comes first. If you are sorting an ArrayList of primitive data types, then Java Collections already provides you with a reverseOrder() comparator.
🌐
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);
🌐
ZetCode
zetcode.com › java › collections-sort
Java Collections.sort - Complete Tutorial with Examples
The Collections.sort method is a utility method in Java's java.util.Collections class. It provides functionality to sort elements in a List.
🌐
Baeldung
baeldung.com › home › java › java collections › comparing long values using collections.sort()
Comparing Long Values Using Collections.sort() | Baeldung
June 16, 2025 - The Collections.sort() method sorts elements in their natural order by default. For numerical types like Long, natural ordering arranges values from smallest to largest.
🌐
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 - Whether we’re working with numerical data or alphabetical strings, Arrays.sort() can arrange the elements in ascending order. Additionally, we can modify the behavior with custom comparators for object arrays. This method is part of the java.util.Arrays class, which provides a suite of utilities for array manipulation. On the other hand, Collections.sort() is designed for sorting instances of the List interface in Java’s Collection Framework.
🌐
YouTube
youtube.com › selenium express
How to sort a collection in java | Collections.sort() | sorting a List | Java interview question |#1 - YouTube
This video is an introduction to java comparable vs comparator series. In this video, we will understand the basics to use the sort() of the Collections clas...
Published: November 23, 2019
Views: 6K
🌐
Jenkov
jenkov.com › tutorials › java-collections › sorting.html
Java Sorting Collections
You can sort these two types of List's. List · LinkedList · To sort a List you do this: List list = new ArrayList(); //add elements to the list Collections.sort(list); When sorting a list like this the elements are ordered according to their ...