我的代码:
HashMap<Integer,Student> Chemistry= new HashMap<Integer,Student>();
Chemistry.put(3333,"NICK");
for (int keys : Chemistry.keySet()){
System.out.println(keys + ":"+ Chemistry.get(keys));
}
输出是:
3333:Student@4aa298b7
答案 0 :(得分:1)
这是你所看到的toString()
上的默认实施。您可以覆盖它以获得更有用的东西。 E.g:
public class Student {
private String name;
// Constructors, methods, the whole nine yards...
@Override
public String toString() {
return "A student called " + name;
}
}