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);
}
}
如何打印键值对
具有多个值的键如何打印
最佳答案
像这样迭代Map或HashMap。
Map<String, Hello> map=new HashMap<>();
Set<Entry<String, Hello>> entries=map.entrySet();
for (Entry<String, Hello> entry : entries) {
String key=entry.getKey();
Hello hello=entry.getValue();
}
关于java - 打印具有多个值的键的 HashMap ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22767759/