Linus海外SEO流量玩家
2015-05-17 10:12
输出为
取得键:1
对应的值为:com.CollectionTest.Student@232204a1
取得键:3
对应的值为:com.CollectionTest.Student@4aa298b7
提上代码
public void testEntrySet() { // 通过entrySet方法返回Map中所有键值对 Set<Entry<String, Student>> entryset = Students.entrySet(); for (Entry<String, Student> entry : entryset) { System.out.println("取得键:" + entry.getKey()); System.out.println("对应的值为:" + entry.getValue()); } }
System.out.println("取得键:" + entry.getKey());
这里输出为啥没加.ID呢
哈哈 机智啊 如果不加等于输出对象的地址
结果我自己发现了问题。。
第六行改为System.out.println("对应的值为:" + entry.getValue().name);
Java入门第三季
409768 学习 · 4463 问题
相似问题