Sort Java Objects Using Comparable And Comparator

There are two interface that can be used to sort objects in a list or array in java. They are java.lang.Comparable and java.util.Comparator. We all know java.util.Arrays and java.util.Collections has sort() method to sort an array or a list. But if you want to make the sorting success, you should let the object in the array or list implement java.lang.Comparable first.