So, now we can sort a list of employees by their id. So we pass User::getCreatedOn to sort by the createdOn field. descending order then use Collections.reverse(list); . If you notice the above examples, the Value objects implement the Comparator interface. Example – Sort POJO or user defined object using comparator interface. To use this class write code as follows: Values are compared in the order they are appended to the builder. We can also use CompareToBuilder class of the Apache Commons Lang library to assist in implementing Comparable.compareTo(Object) methods. The above code can be further re-written as: Here studentlist is the instance of the list containing Student objects … according to the natural ordering of the list items. The Comparator interface in Java is used to sort or … Sorting a List of Objects with Custom Comparator & Function Object. TreeSet is another implementation of Set and is sorted(ordered) using their natural ordering when the Set is created with the default constructor. In order to sort the List of objects we need to implement either Comparable or Comparator interface. We can pass a lambda function in sort () as argument. Similarly, if we want to sort students by their "no", one more comparator (NoComparator.java) can be added and passed it to sort method and data will get sorted by "no". Program: How to get max element of a list of user defined objects using Comparator? In Java, we can implement whatever sorting algorithm we want with any type. Now for employees having the same age, the ordering is decided by the employee’s name. What if we want multiple ways by which the same object can be sorted? For sorting a Java List with Objects, we use Collections.sort()API: – Sorts the specified list according to the order induced by the specified comparator. The equals method returns true if the specified object is equal to this comparator object.. The Comparator.comparing() method accepts a method reference which serves as the basis of the comparison. employeeList.sort(Comparator.comparing(Employee::getId)); Example of sorting using Comparator in java using anonymous class. Learn to use Collections.sort () method to sort arraylist of custom objects in java with examples. The Arrays.sort(locales, localeComparator) call specifies to sort the array of Locale objects using the sort logic in localeComparator, which sorts according to the Local objects' toString() values. We can have multiple sorting ways. For example – Student, Department, Employee, and Payroll class objects. Using Comparator to sort a list of objects. 1. The Comparator.comparing() method accepts a method reference which serves as the basis of the comparison. The new Fruit class implemented the Comparable interface, and overrided the co… 1. Sort List in Natural Ordering. It cannot be done by using default < operator of Player in sort(). In the following example, we will sort User objects by age and name. If you want to do custom sorting we will use comparator in java; We need to use different comparators for sorting objects by different fields. sorting on multiple attributes of the objects. This is where java.util.Comparator comes in. Program: How to search user defined object from a List by using binary search using comparator? For Sorting of List of custom Java Object, you have to do following steps. Sort a List … Vehicle class has following data members. Here I have created Employee object with Name and Age properties, we will be able to sort the list of objects based on … Option 3: List interface sort() [Java 8] Java 8 introduced a sort method in the List interface which can use a comparator. In previous articles, we have discussed how to sort list of objects on the basis of single field using Comparable and Comparator interface Read below articles for sorting ArrayList contents in both ascending and descending order on the basis of single field (i.e. Lets see the new Fruit class again. Comparator interface at a Glance. The value returned by compareTo() method decides the position of the object relative to the specified object. My thoughts… In future, Arrays class should provides more generic and handy method – Arrays.sort(Object, String, flag) . primitive array sort; primitive list sort; object list sort using java.lang.Comparable; object list sort using java.util.Comparator. You can create a separate class and implement a Comparator interface as below. // Specify the comparison rules between 2 Person objects. Sometimes we need to arrange data in an ordered manner which is known as sorting.The sorting can be performed in two ways either in ascending or descending order. Note: In Java 8, the List interface supports the sort() method so you need not to use the Comparator.sort(), instead you can use the List.sort() method. You can use either java.util.Comparator or java.lang.Comparable Comparable provides a 'natural ordering', such as is expected with numbers - you know what their order is. Sort a List … So, we will use other overloaded version of sort(). We would like to sort user defined objects on certain properties/data members. Using Java's sort function is very easy when you have an array or list of simple data types like integer or double, but what happens when you have a more complex object and you want to be able to sort by different fields?. This has a method called compare which lets you search between objects based on its properties. Comparator is used to sort an ArrayList of User-defined objects. All the elements in the list must implement Comparable interface, otherwise IllegalArgumentException is thrown. to store the group of objects. Create Class for objects to be sorted. Storing data in bean is common practice in current industry. ; 1. The class implementing the Comparator interface must define the compare method. In this tutorial you will learn how to use the Comparator interface. Comparator List Sorting In this example showing how to sort objects in the List by using a comparator. A method to provide sorting. sorting - java 8, Sort list of objects by attribute without custom comparator. Output: – According to Oracle: “This implementation is a stable, adaptive, iterative mergesort that requires far fewer than n lg(n) comparisons when the input array is partially sorted, while offering the performance of a traditional mergesort when the input array is randomly ordered. ; 1. Enter your email address to subscribe to new posts and receive notifications of new posts by email. Java 8 Comparator Sorting - Multiple Fields Example using Collections.sort() To sort on a single field then need to use the Comparator.comparing() method from Comparator class.. How to Sort ArrayList in Java. This method is similar to Collections.sort() and you can use it to sort a List of objects using both Comparator and Comparable. this lambda function will compare two Player objects by … Let create a Fruit class: To sort it, you may think of Arrays.sort()again, see below example : Nice try, but, what you expect the Arrays.sort()will do? Objects which implement Comparable interface in Java can be used as keys in a SortedMap like treemap or elements in a SortedSet for example TreeSet, without specifying any Comparator. Using Comparator sort ArrayList on the basis of multiple variables, or simply implement Comparator without affecting the original User-defined class. In this tutorial you will learn how to use the Comparator interface. Comparator: When you want to sort the list of objects of a class,you can use Comparator interface. This article will try to give an example to use both java.lang.Comparable and java.util.Comparator to sort objects. Collections API’s utility class Collections provide a handy way to sort an ArrayList in a natural ordering provided all elements in the list must implement the Comparable interface. Consider a class Named Movie which have 3 fields – id, name and genre [crayon-60042e71de38b935148660/] Create a list of movies and convert with to […] What is the cleanest short way to get this done ? Programmers frequently need to sort elements from a database into a collection, array, or map. Sorting ArrayList that contains custom objects need a different approach than, a ArrayList with primitive types. We can sort the stream elements in natural ordering as well as the ordering provider by Comparator. Given a Array containing Vehicle objects. Description: The Collections.binarySearch() method searches the specified list for the specified user defined object using the binary search algorithm. So the Collections.sort will use this Comparator implementation for sorting the Person objects in the input list. The Comparator interface in Java is used to sort or … Given an array of user defined objects/POJO in java. In order to compare objects we have comparable and comparator in java. This tutorial will present how to order arrays and lists of primitive data and objects. You can create a separate class and implement a Comparator interface as below. We can simply implement Comparator without affecting the original User-defined class. 2. Do NOT follow this link or you will be banned from the site. In java, a Comparator is provided in java.util package. public class PersonComparator implements Comparator { // Override compare methods. Let’s look at a quick example to sort a list of strings. In this post, we will see how to convert List to Map using Stream in java 8. – Sorts the specified list according to the order induced by the specified comparator. So it is preferred to compare objects using multiple fields to avoid such cases. Comparator and Comparable interface along with Collections.sort() method are used to sort the l The collect() method is used to receive elements from a stream and stored them in a collection. Option 3: List interface sort() [Java 8] Java 8 introduced a sort method in the List interface which can use a comparator. Objects that implement this interface can also be used as keys in a sorted map (TreeMap) or as elements in a sorted set (TreeSet), without the need to specify a comparator. We can sort list of class objects by using cmparator. In order to sort a collection of objects (using some property) in Java, we can use the java.lang.Comparable interface which imposes a natural ordering on the objects of each class that implements it. Basically, in Java 7, we were using Collections.sort() that was accepting a List and, eventually, a Comparator – in Java 8 we have the new List.sort(), which accepts a Comparator. Sorting of ArrayList in descending order We generally use Collections.sort () method to sort a simple array list. Create your java POJO class; write your Java.util.Comparator and defind sorting logic Without converting to ArrayList, sorting can be achieved by using TreeSet. However if the ArrayList is of custom object type then in such case you have two options for sorting- comparable and comparator interfaces. Java Sort List. Let us learn how to do that with the help of the code directly. Objects that implement this interface can also be used as keys in a sorted map (TreeMap) or as elements in a sorted set (TreeSet), without the need to specify a comparator. In Java, Collection is a framework that provides interfaces (Set, List, Queue, etc.) Now let’s consider a case where we want to sort employees list based on some user input which is essentially sorting field i.e. By default, this method sorts the unsorted List into ascending order i.e. Translate. employeeList.sort(Comparator.comparing(Employee::getId)); Example of sorting using Comparator in java using anonymous class. If any comparison returns a non-zero result, then that value will be the result returned by toComparison() and all subsequent comparisons are skipped. So we pass User::getCreatedOn to sort by the createdOn field. It then creates a localComparator object that implements the Comparator interface to allow us to sort on the Locale objects' toString() values. Using Comparator sort ArrayList on the basis of multiple variables, or simply implement Comparator without affecting the original User-defined class. Think this way , if you have to sort on multiple properties in same POJO java class for example on name in ascending and on age in descending etc. We will use Arrays.sort method to sort objects. This comparator is then passed to the Collections.sort method. For this, Java already provides 2 classes Comparable and Comparator. If the input array is nearly sorted, the implementation requires approximately n comp… You may skip implementing the equals method if you want to use the default equals method defined in the Object class (which is a superclass of all the Java classes).. In java, a Comparator is provided in java.util package. sometimes he wants to sort by first name, sometimes sort … You can use either java.util.Comparator or java.lang.Comparable Comparable provides a 'natural ordering', such as is expected with numbers - you know what their order is. You have to use java.util.Comparator interface for sorting. In this example, we are going to sort Employee type of list on the basis of the name without implementing Comparator(Employee class will not implement Comparator). In order to sort ArrayList in Descending order using Comparator, we need to use the Collections.reverseOrder() method which returns a comparator which gives the reverse of the natural ordering on a collection of objects that implement the Comparable interface. That’s the only way we can improve. So if the age of the first person object is greater than that of the second person object, it will return a positive integer. Hope you all are aware of what is bean so lets not waste time and understand the code. You can visit my next post: How to sort list of Java Objects by using java.util.Comparator. This tutorial shows how to use java.util.Comparator and java.lang.Comparable to sort a Java object based on its property value. This time we'll understand code of How we can sort List. Typically, this chain can continue further to include other properties as well. When you are sorting on Users, […] Sorting a list of objects is different than sorting a List of String or int. All Rights Reserved. 2. You don’t need to implement Comparator on the class whose objects need to be sorted. When it has custom objects, we need to specify what you really mean by sorting. Sort List in Natural Ordering. The equals method returns true if the specified object is equal to this comparator object.. Here’s how we sort a List of Employee object using Comparable interface in Java: Output: and classes (ArrayList, LinkedList, etc.) Let us know if you liked the post. In this brief article, you will learn how to sort a list using Stream's sorted() method in Java. You may skip implementing the equals method if you want to use the default equals method defined in the Object class (which is a superclass of all the Java classes).. In Java 8, stream() is an API used to process collections of objects. Note that the ComparisonChain stops calling its inputs’ compareTo and compare methods as soon as one of them returns a nonzero result. Sorting a List of Objects with Custom Comparator & Lambda Function We can also sort a list of Player objects by name using a Lambda function instead of defining a seperate Function object like above. Comparator is used to sort an ArrayList of User-defined objects. In this brief article, you will learn how to sort a list using Stream's sorted() method in Java. std::list::sort has an another overloaded version that accepts a function pointer as an … All the elements in the list must implement Comparable interface, otherwise IllegalArgumentException is thrown. Here HashMap values are sorted according to Integer values. How to sort a List of objects using Comparator in Java. 1. Java sort arraylist of objects – Comparator Example. ; member variable). A Comparator is a comparison function, which provide an ordering for collections of objects that don’t have a natural ordering. In this post, we will see how to sort a List of objects using Comparable in Java. We can use Collections.sort () method to sort a list in the natural ascending order. [{name='Joe', age=10}, {name='John', age=15}, {name='Dan', age=20}, {name='Sam', age=20}, {name='Will', age=20}]. In previous articles, we have discussed how to sort list of objects on the basis of single field using Comparable and Comparator interface Read below articles for sorting ArrayList contents in both ascending and descending order on the basis of single field (i.e. 4. Sorting ArrayList using Comparable and Comparator; Sorting ArrayList in descending order Java Object Sorting Example How do you sort a list of Objects in Java is one of the frequently asked coding questions in Java interviews and surprisingly not every Java programmers know How sorting of object happens in Java. You don’t need to implement Comparator on the class whose objects need to be sorted. 3. To achieve this we can use either Comparator and Comparable. In this post, we will see how you can use comparator to sort list of objects in java. Java Stream List to Map. We have to pass Comparator object in it. This tutorial will present how to order arrays and lists of primitive data and objects. Comparator interface. We can easily sort the employee’s list first by age, and then by name as shown below. Using Comparator we can sort ArrayList on the basis of multiple variables. Sort by created date ascending The class implementing the Comparator interface must define the compare method. Here we will learn how to sort a list of Objects in Java. So we pass User::getCreatedOn to sort by the createdOn field. In the Collections.sort, we will pass appropriate Comparator… For example, in our case we can sort Employee object using id, firstName and lastName also. Furthermore, using the Comparator, we can manipulate complex sorting conditions, e.g. For example, a User object might have properties age and name. The above code will sort the employee’s list only by the age field. It is possible to sort an ArrayList in Java without using Comparator or Comparable interface. Note: I have added few helper functions that really helps while coding like print – this takes array list of objects and prints in format I want instead of class id and all that. You didn’t even mention what to sort in the Fruit class. Therefore if an object implements the Comparable interface, then the Lists (and arrays) of that object can be sorted automatically by Collections.sort (and Arrays.sort). – Use Collections.sort() method or Java 8 List.sort() to in-place sort the ArrayList, Java 8 Stream.sorted() to return a new sorted ArrayList of Objects without affecting the original List. if we have already fetched list of objects from db and then want to sort in-memory to cater different use case to fulfill business requirement. This class’s implementor needs to override the abstract method compare() defined in java.util.Comparator which compares its two arguments for order. Note that we have simply reduced the value of int primitive type age from each other while for the String object, built-in comparison function compareTo() is used. Primitive Type List, Wrapper Classes Type List can be sorted by using the Collection.sort(), but Object type List can’t be sorted. You can also use List.sort() method to sort a List of objects. With Comparator we have even more flexibility and we can compare based on various properties. Sort an ArrayList. Notify of new replies to this comment - (on), Notify of new replies to this comment - (off). In java, Comparator is provided in java.util package. These classes store data in an unordered manner. Sort by created date ascending We can use Collections.reverseOrder () method for reverse sorting. Here comes the comparator interface to the rescue. Sorting ArrayList with basic types is easy. Collectors’s toMap() can be used with Stream to convert List to Map in java. Sort linkedlist using comparator in java example program code: We can use Collections.sort() method to sort linkedlist using comparator in java. – For Descending order, just use additional Comparator.reversed() method. The java.lang.Comparable and java.util.Comparator are powerful but take time to understand and make use of it, may be it’s due to the lacking of detail example. Option 3: List interface sort() [Java 8] Java 8 introduced a sort method in the List interface which can use a comparator. Comparator is used to sort an ArrayList of User-defined objects. Here is an example that sort the list … We can use Guava’s ComparisonChain for performing a chained comparison statement inside compareTo() method as shown below: The return value of compareTo() method will have the same sign as the first non-zero comparison result in the chain, or will be zero if every comparison result was zero. Basically, in Java 7 we were using Collections.sort() that was accepting a List and, eventually, a Comparator - in Java 8 we have the new List.sort() that accepts a Comparator. The toList() return the collector which collects all the input elements into a list, in encounter order. We can use Collections.sort() method to sort a list in the natural ascending order. | Sitemap, Java sort arraylist of objects – Comparable and Comparator example. Here is the complete code: Basically, in Java 7, we were using Collections.sort() that was accepting a List and, eventually, a Comparator – in Java 8 we have the new List.sort(), which accepts a Comparator. Comparator A Comparator interface is […] In this example, we are going to sort Employee type of list on the basis of the name without implementing Comparator(Employee class will not implement Comparator). Java Sort List Here we will learn how to sort a list of Objects in Java. Bean structure allows us to get specific property of object. The above code can be further re-written as: Here studentlist is the instance of the list containing Student objects … If two employees have same age, their relative ordering in the sorted list is not fixed. Let’s look at an example where our value is a custom object. – According to Oracle: “This implementation is a stable, adaptive, iterative mergesort that requires far fewer than n lg(n) comparisons when the input array is partially sorted, while offering the performance of a traditional mergesort when the input array is randomly ordered. package org.o7planning.tutorial.comparator; import java.util.Comparator; // This class implements the Comparator interface // It can be considered as the rule to compare the Person objects. Description: Collections.min() method returns the minimum element of the given collection, according to the order induced by the specified comparator. Date.java Sorting the HashMap using a custom comparator . How about a Java Object? primitive array sort; primitive list sort; object list sort using java.lang.Comparable; object list sort using java.util.Comparator. The JDK 8 added a couple of more methods on both java.util.Comparator class and java.util.List to make sorting easier. A Comparator is more useful when there could be multiple was to order (such as with students) or when you want to order on something other than the 'natural order'. [{name='Joe', age=10}, {name='John', age=15}, {name='Sam', age=20}]. Using Comparator.comparing(). Sort ArrayList of Objects by field in Java Now we’re gonna sort ArrayList of Date items by field name (and don’t care about other fields). In order to sort the List of objects we need to implement either Comparable or Comparator interface. This class’s implementor needs to override the abstract method compareTo() defined in java.util.Comparable which compares the object with the specified object. So, it will hits the following error : To sort an Object by its property, you have to make the Object implement the Comparable interface and override the compareTo()method. Understand the code directly original User-defined class java.util.Comparator and java.lang.Comparable to sort a list of that! Which lets you search between objects based on its properties according to the induced! List only by the createdOn field in this tutorial will present how to sort an ArrayList in descending order generally!:Getcreatedon to sort a list of objects of a class to provide an for. Approach is to create two comparators one for age and another for name the basis of the rules. Comparator example and Comparable interface, otherwise IllegalArgumentException is thrown array, or simply implement Comparator on the basis multiple! Collections.Sort method in future, Arrays class should provides more generic and handy method – Arrays.sort ( object ).! Search between objects based on its property value – Comparable and Comparator in Java as soon as one of returns! Your java.util.Comparator and java.lang.Comparable to sort a list of Java objects by age and name operator of Player sort... It is possible to sort an ArrayList of User-defined objects value is a comparison function, provide. Comparator implementation for sorting of ArrayList in descending order then use Collections.reverse ( list ;. Class, you need two things – a class, you have two options for Comparable. Can simply implement Comparator on the class implementing the Comparator interface can further... Sorting can be achieved by using cmparator using the Comparator interface must define the compare method you all are of! Collection, according to the order they are appended to the order they are appended to the order induced the. For order comparison function, which provide an ordering sorting a list of objects using multiple fields to such! List using stream in Java, Comparator is used to receive elements from a stream and stored them a... Primitive list sort using java.lang.Comparable ; object list sort using java.util.Comparator, array, or Map us! Can create a separate class and java.util.List to make sort list of objects in java without comparator easier – for descending order then Collections.reverse. Can manipulate complex sorting conditions, e.g order induced by the specified list according to the specified Comparator can! See: sorting a list by using a Comparator for more information, see: sorting list... List items provided in java.util package which compares its two arguments for order Comparator. Classes Comparable and Comparator is common practice in current industry to new posts by email code will sort defined! A stream and stored them in a collection, array, or Map l how a! Use CompareToBuilder class of the comparison id, firstName and lastName also with Collections.sort ( ) method sort. Equals method returns true if the ArrayList is of custom Java object ordering... Java.Lang.Comparable ; object list sort using java.lang.Comparable ; object list sort using java.util.Comparator storing data in bean common... ) methods address to subscribe to new posts by email of sorting Comparator! – Student, Department, Employee, and then by name as shown.... Or Comparable interface, otherwise IllegalArgumentException is thrown a framework that provides interfaces ( Set,,! You notice the above code will sort the list of objects of a class, you need things... This comment - ( on ), notify of new posts by email implementing the Comparator as... Than, a Comparator interface object type then in such case you have to do following steps we would to... For employees having the same age, the ordering provider by Comparator can implement whatever sorting algorithm we want any. Of objects in Java using anonymous class method – Arrays.sort ( object ) methods method. Use Collections.reverseOrder ( ) as argument Java using anonymous class comparison function, which provide an ordering for of! By the Employee ’ s list first by age, the ordering by... A Comparator interface must define the compare method other overloaded version of sort ( ) are... The natural ordering easily sort the list … using Comparator sort ArrayList the... The specified list according to Integer values with Collections.sort ( ) method accepts a method reference which serves the... All the elements in the list of custom Java object based on its value! Us learn how to sort list of objects of a class, can. Objects in the order induced by the age field property value compare which lets search... T have a natural ordering of the code Comparator on the class objects. Following example, a Comparator interface as below notifications of new replies to this comment - ( on,.:Getcreatedon to sort or … all Rights Reserved properties age and name to make easier... Do following steps class of the comparison class ’ s list only the! Can create a separate class and implement a Comparator is then passed to the induced! In descending order, just use additional Comparator.reversed ( ) method for reverse sorting ) be. Soon as one of them returns a nonzero result you can create a separate and... We can use Collections.sort ( ) method to sort elements from a and... Compare ( ) method to sort a Java object other sort list of objects in java without comparator as well as the ordering decided... Of Player in sort ( ) as argument according to Integer values Employee object using the search! Convert list to Map ComparisonChain stops calling its inputs ’ compareTo and compare methods collection, according to Collections.sort. Is of custom Java object object is equal to this comment - on... Or Map we want multiple ways by which the same object can be sorted Java objects attribute..., in our case we can pass a lambda function in sort ( ) is an API used sort... Or simply implement Comparator without affecting the original User-defined class ) methods multiple fields to avoid cases... The Person objects in Java to provide an ordering according to the order by... Properties/Data members minimum element of the given collection, array, or Map time we understand! Objects in Java, we need to specify what you really mean by sorting an API used process... Java using anonymous class other properties as well as the ordering is by. Method in Java without using Comparator in Java primitive data and objects we... … using Comparator we can use Collections.reverseOrder ( ) defined objects/POJO in Java java.util.Comparator and defind sorting logic is... Ordering in the order induced by the Employee ’ s the only way we can easily the. Subscribe to new posts by email list by using default < operator of Player sort... Inputs ’ compareTo and compare methods further to include other properties as well as the basis of comparison! Must define the compare method function, which provide an ordering in sort ( ) searches! Java is used to sort an ArrayList of custom object stream 's sorted )! Will present how to sort an ArrayList of User-defined objects interface must define the compare.... Object relative to the specified object is equal to this Comparator is used sort! Such case you have two options for sorting- Comparable and Comparator handy method – (. Class objects by using java.util.Comparator override the abstract method compare ( ) is an API used sort! Must implement Comparable interface along with Collections.sort ( ) method to sort list < >!, Queue, etc. the class sort list of objects in java without comparator the Comparator interface must define compare. From a list of objects that don ’ t even mention what to linkedlist... Employee object using id, firstName and lastName also a custom object type then in such case you have options. Objects implement the Comparator, we will sort the l how about a Java,... Similar to Collections.sort ( ) method to sort or … all Rights Reserved Comparator: When you want sort!, Java sort ArrayList of User-defined objects see how you can create a separate class and java.util.List make... Objects is different than sorting a list of Java objects by using TreeSet to use Collections.sort ( method... To Map aware of what is the cleanest short way to get specific property of object Integer values a ordering. Sorting can be sorted implementing the Comparator interface as below lists of primitive and... Allows us to get this done implements Comparator < Person > { // override compare methods of variables... Define the compare method this has a method called compare which lets you search between objects on. ) methods:getId ) ) ; example of sorting using Comparator or Comparable interface otherwise! The following example, we will see how to sort a list employees! Descending order, just use additional Comparator.reversed ( ) can be achieved by using java.util.Comparator that... Frequently need to specify what you really mean by sorting use other overloaded version of sort ( ) can used! About a Java object a database into a collection, array, or Map two for! Allows us to get this done of employees by their id way we can pass lambda... Decided by the createdOn field this tutorial will present how to sort on! A ArrayList with primitive types program code: Comparator is provided in java.util package minimum element the... Class whose objects need to implement Comparator without affecting the original User-defined class do that with the of... Stored them in a collection is to create two comparators one for age and for... Comparator sort ArrayList on the basis of the given collection, array, or simply implement Comparator on the of! Provides more generic and handy method – Arrays.sort ( object, you need two things – a class, need... Comparator we can use it to sort linkedlist using Comparator to sort the list by using.... Array sort ; object list sort using java.lang.Comparable ; object list sort ; primitive list sort using ;! To include other properties as well as the basis of multiple variables, or simply implement Comparator without the.