A good way to sort Java collection objects is using Comparable and Comparator interfaces. A developer can use Collections.sort()
, the elements are sorted based on the order mention in compareTo()
.
When a developer uses Collections, sort (Comparator), it sorts the objects depend on compare()
of the Comparator interface.