import java.util.Comparator;
import java.util.Scanner;
import java.util.TreeSet;
import com.heima.bean.employee;
public class linaxi_1 {
public static void main(String[] args) {
TreeSet<employee> tr = new TreeSet<employee>(new Comparator<employee>() {
public int compare(employee e1, employee e2) {
double num = (e2.getSalary()-e1.getSalary());
double age1 = num ==0?e1.getAge()-e2.getAge():num;
return (int) (num ==0? e1.getName().compareTo(e2.getName()):num);
}
});
tr.add(new employee("张三",23,4000));
tr.add(new employee("李四",24,1000));
tr.add(new employee("周七",23,1000));
tr.add(new employee("王五",25,5000));
for (employee e : tr) {
System.out.println(e);
}
}
} |