HashMap<Studeent,String> hm = new HashMap<Student,String>();
hm.put(new Student("lisi",38),"北京");
hm.put(new Student("zhaoliu",24),"上海");
hm.put(new Student("xiaoqiang",31),"沈阳");
hm.put(new Student("wangcai",28),"大连");
hm.put(new Student("zhaoliu",28),"铁岭");
Set<Student> keySet = hm.keySet();
Itertor<Student> it =keySet.iterator();//Itertor<Student> it = hm.keySet().iterator();
while(it.hasNext)(){
Student key = it.next();
String value = hm.get(key);
System.out.println(....)
就是毕老师视频里面那段代码 为什么这么添加的时候 Lisi不会覆盖 。这个键的比较不应该是默认的吗。为什么还要自己加入比较方法? |