class StuNameComparator implements Comparator<Student>//1、自定比较器StuNameComparator
{
public int compare(Student s1,Student s2)
{
int num = s1.getName().compareTo(s2.getName());
if(num==0)
return new Integer(s1.getAge()).compareTo(new Integer(s2.getAge()));
return num;
}
}
class MapTest2
{
public static void main(String[] args)
{
TreeMap<Student,String> tm =
new TreeMap<Student,String>(new StuNameComparator());//2、new 对象时传入自定义比较器StuNameComparator