class Seat implements Comparable<Seat>{
int x,y;
public Seat(int i, int j) {
this.x=i;
this.y=j;
}
@Override
public int compareTo(Seat o) {
return this.x!=o.x?this.x-o.x:this.y-o.y;//先根据x排序,在根据y
}
@Override
public String toString() {
return "(" + x + ","+ y + ")";
}
}
class Student{
String name;
public Student(String name) {
super();
this.name = name;
}
@Override
public String toString() {
return name +"同学";
}
}
public class test5 {
public static void main(String[] args) {
TreeMap<Seat, Student> s161 = new TreeMap<Seat, Student>();
s161.put(new Seat(1,1), new Student("张三"));
s161.put(new Seat(1,2), new Student("李四"));
s161.put(new Seat(2,1), new Student("王五"));
s161.put(new Seat(2,2), new Student("赵六"));
System.out.println(s161);
Map.Entry<Seat, Student> r=s161.firstEntry();//寻找第一位位置同学
System.out.println(r.getKey()+"->"+r.getValue());
}
}