You need to write a Comparator.
class EmployeeAgeComparator implements Comparator
{
@Override
public int compare(Employee e1, Employee e2)
{
if (e1.getAge() > e2.getAge())
{
return -1;
}
else if (e1.getAge() < e2.getAge())
{
return 1;
}
return 0;
}
}
Then use Collections.sort method like this.
Collections.sort(empList, new EmployeeAgeComparator());
Hope this helps.