In this example we will learn how to sort a java.util.ArrayList using the Sort method of the Collection API. Lets now see how to do it. [Read more…]
In my previous tut you would have learnt how to sort objects in a ArrayList using java comparator. It is almost the same as the previous instead of a seperate class for the implementing the Comparator we can implement it in the same Employee Class and we have to override compareTo method instead of compare method. So let see how to sort objects based on the Comparable interface.
Sorting the ArrayList or any Collection which has the primitive is easy. You can simply use the Sort method in Collection but thats not the case in real world situation you may be required to sort the objects based on the certain criteria. So first lets see how to sort the primitives.