java - Update entry while iterating through key set -
how accomplish updating entry while iterating through keys
map<string,list<sobject>> map1=new hashmap<string,list<sobject>>(); map<string,list<sobject>> map2=new hashmap<string,list<sobject>>(); for(string name: map1.keyset()){ //do for(sobject obj1: map1.get(name)){ //iterate through list of sobjects returned key for(sobject obj2 : map2.get(name)){ //iterate through list of sobject values keys , update or remove values related key } } }
you can use iterator on map's entryset - map.entryset().iterator()
make sure nothing else modifying map while you're iterating through it, own modifications safe long you:
- remove items using iterator's remove() method, , - modify value using map.entry setvalue() method
see http://docs.oracle.com/javase/6/docs/api/java/util/map.html#entryset()
Comments
Post a Comment