How to sort a list of custom objects using comparable in java / How to implement Comparable in java

Suppose you have a list which contains objects of your own class rather than java’s built in classes such as java.lang.Integer, java.lang.String etc. Now you want this list to be sorted on a particular field of this class. Let’s say we have a User class which contains user details such as name, age, address etc., and we have a list of various users.
Now we want a list wherein users are listed in the order of their increasing age. That is, we need to sort the above list in the order of age. (more…)

Continue Reading
Close Menu