Object Sorting in java

Tue, Nov 19, 2019

Read in 1 minutes

In this article, you are going to explore the sorting using Comparable Interface. This Interface has to be used when you want to sort your objects.

For example, in an employee class, you have properties Employee Name, Employee Experience, Employee Performance Rank. You have a collection of Employee Objects which is unordered. You need to sort by year-of-experience property. So, for this case, you have to implement the Comparable interface in employee class and you need to implement the compareTo() method.

employee.java Employee

sortingdemo.java sortingdemo

Key Points

Conclusion