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());
Related Posts:
- How to sort an ArrayList?
- Why is there no SortedList in Java?
- Sort a Map
by values - How to use Comparator in Java to sort
- How to sort a HashSet?
- What are the differences between a HashMap and a Hashtable in Java?
- When to use LinkedList over ArrayList in Java?
- Difference between Arrays.asList(array) and new ArrayList
(Arrays.asList(array)) - Initialization of an ArrayList in one line
- Spring Boot – Unable to resolve Whitelabel Error Page
- Difference between HashSet and HashMap?
- How to sort with lambda in Python
- Python list sort in descending order
- C library function to perform sort
- Spring @PropertySources value not overriding
- Java Ordered Map
- java Arrays.sort 2d array
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘MyController’:
- How to convert List
to int[] in Java? - Error creating bean with name ‘entityManagerFactory’ defined in class path resource : Invocation of init method failed
- Printing HashMap In Java
- How to convert int[] into List
in Java? - Spring boot – Request method ‘POST’ not supported. Tried everything
- Error creating bean with name ‘entityManagerFactory’ defined in class path resource : Invocation of init method failed
- Sorting HashMap by values
- Will Arrays.sort() increase time complexity and space time complexity?
- Difference between spring @Controller and @RestController annotation
- Sort a single String in Java
- How do I efficiently iterate over each entry in a Java Map?
- HashSet vs. ArrayList
- FIFO based Queue implementations?
- @Autowired – No qualifying bean of type found for dependency
- Create a List of primitive int?
- Easiest way to convert a List to a Set in Java
- UnsatisfiedDependencyException: Error creating bean with name
- UnsatisfiedDependencyException: Error creating bean with name
- How to convert int[] to Integer[] in Java?
- Change priorityQueue to max priorityqueue
- How to sort 2d array by row in python?
- Collections.emptyMap() vs new HashMap()
- Why SpringMVC Request method ‘GET’ not supported?
- How to sort an array of objects in Java?
- Any implementation of Ordered Set in Java?
- How to sort an array of objects in Java?
- Any implementation of Ordered Set in Java?
- java sort using anonymous class
- Most efficient way to increment a Map value in Java
- How to solve the “failed to lazily initialize a collection of role” Hibernate exception
- Why is the minimalist, example Haskell quicksort not a “true” quicksort?
- Java Array Sort descending?
- Median of Medians in Java
- Why does heap sort have a space complexity of O(1)?
- How to upload a file and JSON data in Postman?
- Sort ArrayList of custom Objects by property
- Why is a ConcurrentModificationException thrown and how to debug it
- Union or intersection of Java Sets
- How can I sort a Perl hash on values and order the keys correspondingly (in two arrays maybe)?
- Using insertion sort for descending order?
- Why quicksort is more popular than radix-sort?
- Spring boot: Unable to start embedded Tomcat servlet container
- Elasticsearch ordering by field value which is not in the filter
- model.addAttribute() parameters
- What does Java option -Xmx stand for? [duplicate]
- How do I convert a String to an int in Java?
- What does Java option -Xmx stand for? [duplicate]
- Is there an invisible character that is not regarded as whitespace?
- Problem with gif with transparent background
- Finding white rectangle in an image
- 1000 * 60 * 60 * 24 * 30 results in a negative number [duplicate]
- How to convert nanoseconds to seconds using the TimeUnit enum?
- Search for words with telephone numbers from 2-3-4 tree
- how to sort pandas dataframe from one column
- Using or ‘|’ in regex [duplicate]
- How to format strings in Java
- How do I sort a dictionary by value?
- What is the difference between x86 and x64
- How do I sort a dictionary by value?
- && (AND) and || (OR) in IF statements
- How to use the toString method in Java?
- What is a NullPointerException, and how do I fix it?
- What exactly is Apache Camel?
- Sorting an array of objects by property values
- Unable to find valid certification path to requested target – error even after cert imported
- Unable to find valid certification path to requested target – error even after cert imported
- What is the equivalent of the C++ Pair
in Java? - Java – Convert integer to string [duplicate]
- Getting random numbers in Java [duplicate]
- What is an instance variable in Java?
- javac is not recognized as an internal or external command, operable program or batch file [closed]
- javac is not recognized as an internal or external command, operable program or batch file [closed]
- Java: “error: cannot find symbol”
- What is lexicographical order?
- How does the Java ‘for each’ loop work?
- How do I sort a dictionary by value?
- Which is the difference between Long.valueOf(0) and 0L in Java?
- What is a StackOverflowError?
- Use of “instanceof” in Java [duplicate]
- How to uninstall Eclipse?
- Is GNU’s Java Compiler (GCJ) dead? [closed]
- How does System.out.print() work?