-1

I have collection of employees with states as name,salary,id.

    TreeSet ts=new TreeSet();
    ts.add(new Employee("neeraj", 10000, 123));
    ts.add(new Employee("neeraj", 10000, 789));
    ts.add(new Employee("ankit", 30000, 345));
    ts.add(new Employee("ankit", 40000, 456));

How to sort employees with unique name on basis of salary?

  • Implement `Comparator` interface and use this implementation along with your collection upon sorting. –  Apr 01 '17 at 19:05
  • The [duplicate](http://stackoverflow.com/q/4258700/5221149) is old, but does have a Java 8 answer [further down](http://stackoverflow.com/a/36367245/5221149). – Andreas Apr 01 '17 at 19:08

1 Answers1

0

Java 8 solution:

Collections.sort(employees, Comparator.comparing(Employee::getName)
    .thenComparing(Report::getSalary));
Alex Romanov
  • 11,453
  • 6
  • 48
  • 51