import java.util.Comparator;
import java.util.TreeMap;
public class Test3 {
public static void main(String[] args) {
TreeMap<Student,String> tm=new TreeMap<>(new Comparator<Student>(){
@Override
public int compare(Student s1, Student s2) {
int num=s1.getAge()-s2.getAge();
return num==0?s1.getName().compareTo(s2.getName()):num;
}
});
tm.put(new Student("张三", 23), "北京");
tm.put(new Student("李四",24), "上海");
tm.put(new Student("王五",25), "北京");
System.out.println(tm);
}
}
|
|