I have a very simple code to populate hashmap with arrayList. Following is the code snippet
HashMap<String, ArrayList<String> > fieldValue = new HashMap<String, ArrayList<String>>();
ArrayList<String> tmp = new ArrayList<>();
tmp.add("f");
tmp.add("string");
tmp.add("false");
fieldValue.put("bas", tmp);
tmp.clear();
tmp.add("f");
tmp.add("string");
tmp.add("false");
fieldValue.put("usc", tmp);
tmp.clear();
tmp.add("f");
tmp.add("int");
tmp.add("false");
fieldValue.put("st", tmp);
for (Map.Entry r : fieldValue.entrySet()) {
System.out.println(r.getKey() + "\t" + r.getValue());
}
Following is the output when I execute it
st [f, int, false]
usc [f, int, false]
bas [f, int, false]
Where is the problem? I was expecting there different values in hashmap value but they are all same. Am I missing something?