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
- How to set a Timer in Java?
- How to parse JSON in Java
- Can’t execute jar- file: “no main manifest attribute”
- Casting variables in Java
- What’s the simplest way to print a Java array?
- Does a Java to C++ converter/tool exist?
- How change the color arrowIcon to JMenu when it is selected
- Why would a “java.net.ConnectException: Connection timed out” exception occur when URL is up?
- String interpolation in Java 14 or 15
- How do I save a String to a text file using Java?
- method in class cannot be applied to given types
- HTTP Status 405 – Request method ‘POST’ not supported (Spring MVC)
- “NoClassDefFoundError: Could not initialize class” error
- Implements vs extends: When to use? What’s the difference?
- Using a comparator function to sort
- Ubuntu: OpenJDK 8 – Unable to locate package
- What is a Question Mark “?” and Colon “:” Operator Used for?
- How to remove single character from a String
- org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when ‘hibernate.dialect’ not set
- How to sort a list of objects based on an attribute of the objects?
- Is there a concurrent List in Java’s JDK?
- Subtracting two lists in Python
- cannot make a static reference to the non-static field
- Double cannot be dereferenced?
- Encrypt Password in Configuration Files?
- Java, Simplified check if int array contains int
- Converting a string to an integer on Android
- Error: Generic Array Creation
- What is method hiding in Java? Even the JavaDoc explanation is confusing
- Error: class X is public should be declared in a file named X.java
- Parsing JSON string in Java
- java attempting to assign weaker access privilege error
- Getting a “no interface expected here” when I try to subclass ServiceConnection [duplicate]
- How to determine day of week by passing specific date?
- set background color: Android
- Class JavaLaunchHelper is implemented in two places
- What’s the equivalent of Java’s Thread.sleep() in JavaScript?
- No Main class found in NetBeans