问答详情
源自:5-3 学生选课---删除 Map 中的学生

testEntrySet方法问题

输出为

取得键: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());
}
}


提问者:Linus海外SEO流量玩家 2015-05-17 10:12

个回答

  • Willim_Don
    2016-03-27 15:01:10

    System.out.println("取得键:" + entry.getKey());

    这里输出为啥没加.ID呢

  • Hjava
    2015-05-19 19:07:52

    哈哈 机智啊  如果不加等于输出对象的地址

  • Linus海外SEO流量玩家
    2015-05-17 10:14:14

    结果我自己发现了问题。。

    第六行改为System.out.println("对应的值为:" + entry.getValue().name);