map.put(new Student("Tom", 77), 1);
map.put(new Student("Bob", 66), 2);
map.put(new Student("Lily", 99), 3);
for (Student key : map.keySet()) {
System.out.println(key);
}
System.out.println(map.get(new Student("Bob", 66)));
//这个get方法中的参数66,不管姓名是什么样的,只要分数是66,就返回2,很迷。
添加语句: && p1.name.equals(p2.name)
public int compare(Student p1, Student p2) { if (p1.score == p2.score && p1.name.equals(p2.name)) { return 0; } return p1.score > p2.score ? -1 : 1; }
谢谢
Sign in to make a reply
我是你爹币
map.put(new Student("Tom", 77), 1);
map.put(new Student("Bob", 66), 2);
map.put(new Student("Lily", 99), 3);
for (Student key : map.keySet()) {
System.out.println(key);
}
System.out.println(map.get(new Student("Bob", 66)));
//这个get方法中的参数66,不管姓名是什么样的,只要分数是66,就返回2,很迷。