HashMap 只有一个键和一个值
Map<String, String> hm = new HashMap<>();
hm.put("one","ele");
现在如何从中获取键和值并分配给字符串?
最佳答案
只需迭代它们
for (Entry<String, String> entry : hm.entrySet())
{
String key = entry.getKey();
String value = entry.getValue();
System.out.println(key + ":" + value);
}
而且您也不需要使用 HashMap,因为您只有 1 个键值对。
关于java - 如何从 HashMap 中检索值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27354481/