forum

home / developersection / forums / how to get a highest (last) element in treeset when treeset is sorted with other attribute

How to get a highest (last) element in treeset when treeset is sorted with other attribute

Royce Roy 1960 29-Apr-2015
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 ] 


Updated on 29-Apr-2015
Can you answer this question?

Answer

1 Answers

Liked By