我正在尝试将值插入哈希图中。我将它放在一个循环中,因为正在从字符串列表中检索值。代码如下:
HashMap<String, String> resultHashMap = new HashMap<String, String>();
//add the top document id back to the resultHashMap
resultHashMap.put("entryObject", dsStepParam.getValue());
for(String res : results)
{
log.info(res);
resultHashMap.put("dataObject", res);
}
hashMap(在这个循环之后应该包含以下内容:
{"entryObject":"500386787",
"dataObject":"500386883;500901929",
"dataObject":"500386906;500901969",
"dataObject":"500386787;500901666",
"dataObject":"500386784;500901654",
"dataObject":"500386762;500901599"}
但实际内容是:
{"entryObject":"500386787",
"dataObject":"500386762;500901599"}
如您所见,它仅存储 entryObject 和最后一个 dataObject。如何让它将所有值存储在 hashMap 中?