Google News
logo
Java Collections - Interview Questions
What is a good way to sort the Collection objects in Java?
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.
Advertisement