I wrote the following code to associate a key with a list of strings.When I display it,the values of the list for key '2' is being replaced by the values for key '4'.Shouldn't '2' point to the values it was mapped to?
Map<Integer,List<String>>hm=new TreeMap<Integer,List<String>>();
List<String>l=new ArrayList<String>();
l.add("tree");
l.add("tyre");
hm.put(2, l);
l.clear();
l.add("treaaae");
l.add("tyret");
l.add("treeeqqq");
l.add("tyreqww");
hm.put(4, l);