[英]How to add HashMap values to List and print the same
我正在嘗試將地圖值添加到我的方案的列表中,如下所示。
我有select語句,該語句返回n-no的列和行,我將它們存儲到String類型的Hash Map列表中,並將其傳遞給其他方法以從結果中生成EXCEL文件。
我看不到列表中的任何數據
請告訴我我要去哪里錯了。
while (result.next()) {
resultValues.put("PARTC_ID",result.getString("PARTC_ID"));
resultValues.put("FILE_NME",result.getString("FILE_NME"));
resultValues.put("LOC_ID",result.getString("LOC_ID"));
resultValues.put("CRTE_DTE",result.getString("CRTE_DTE"));
resultValues.put("CRTE_BY",result.getString("CRTE_BY"));
value.add(resultValues); resultValues.clear(); System.out.println(value);
}
將地圖添加到列表后,您正在清除地圖。 因此,地圖引用都是相同的(並且為空)...我想您想進行此更改-
// resultValues.clear(); // No, if you need another Map... do this
resultValues = new HashMap<String, String>();
然后迭代您的值List嘗試
for (HashMap<String, String> map : value) {
for (String key : map.keySet()) {
System.out.printf("key[%s] = %s\n", key, map.get(key));
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.