I am using a treeset which contains employee class
TreeSet<Employee> ts = new TreeSet<Employee>(new ComparatorEmpId());
Requirements :
1)My treeset should be sorted by employee Id
2)(But I want to get the highest salaried employee from treeset (using last) . how do i do that ?
3)[I tried to use comparator for sorting the employee Id , but for getting a highest salary I should have had the salary attribute sorted ]
Anonymous User
29-Apr-2015In Java 8 you could also use streams for that:
This assumes there is method public int getSalary() in Employee class.