I have a ConcurrentHashMap in the below format:
ConcurrentHashMap<String,ConcurrentHashMap<String,ArrayList>>
Now in this map,I want to remove a particular value in the array list.Can anybody guide with this.
EDIT1:
I have a map
<“packet1”–><“NR1”,[Pr1,Pr2]>>
<“packet1”–><“NR2”,[Pr1,Pr2]>>
Now when i remove map.get(“packet1”).get(“NR1”).remove(“Pr2”) it removes Pr2 from both NR1 and NR2.Isnt should remove only from NR1.Am i doing anything wrong here.plz update me,
P.S : I am updated the map for the second time for the same key packet1 with both values NR1 and NR2
You’ve made a mistake setting up the map. When you added the lists for NR1 and NR2, you used the same list object. Your map now contains two references to that list. When you remove the element from the NR1 list, you’re removing it from the same list that is visible under NR2.
The solution is to fix your code, so that when you insert a list into the map, you insert a different list for each key.
You say in a comment on JB’s post that you didn’t do this. The fact is, you did do this. You just haven’t realised it yet!