Java Advanced Sorting

Java Advanced Sorting

In the List Sorting Article, you learned how to sort lists alphabetically and numerically, but what if the list has objects in it?

To sort objects you need to specify a rule that decides how objects should be sorted. For example, if you have a list of cars you might want to sort them by year, the rule could be that cars with an earlier year go first.

The Comparator and Comparable interfaces allow you to specify what rule is used to sort objects.

Being able to specify a sorting rule also allows you to change how strings and numbers are sorted.


Continue reading Java Advanced Sorting