I have HashMap HashMap<Integer, List<String>> storeR and it stores "22,name1,name2"..but is there any way to remove name1 from the 22? i just want to remove only name 1 from 22. How do i do that.?I hope you can help me with it. Thank you.
3 Answers
Given the questions you've asked around this, you'd be better off using a third party library: Guava has a Multimap interface with various implementations - you'd probably want ArrayListMultimap.
You can then just write:
multimap.remove(22, "name1");
If you really want to keep doing all the work manually yourself, you can call get on the map to return the list, and then remove on the list to remove the value. But you should consider whether you want to also remove the key entirely if you've removed the last value - and of course if you don't know whether the key already exists in the map, you need to only conditionally call remove...
Comments
ArrayListMultimap in Guava is designed for the case.
See: http://code.google.com/p/guava-libraries/wiki/NewCollectionTypesExplained#Multimap
HashMapandList?