【发布时间】:2023-03-17 14:55:01
【问题描述】:
class hello {
string name;
int number;
}
class object {
public static void main(string args[]) {
HashMap hs = new HashMap();
hello c1 = new hello();
hello c2 = new hello();
hs.put("india",c1);
hs.put("america",c2);
}
}
如何打印键值对
具有多个值的键如何打印
【问题讨论】:
-
HashMap具有完美的toString表示,如果您在hello类中覆盖toString方法。你也应该覆盖equals和hashcode。 -
不要调用类
object。也不要叫它Object。
标签: java