0

キーを反復処理しながら、エントリの更新をどのように達成しますか

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 something

   for(SObject obj1: Map1.get(name)){
    //iterate through the list of SObjects returned for the key 

        for(SObject obj2 : Map2.get(name)){
        //iterate through the list of SObject values for the keys and update or remove the values related to the key
        }
   }
 }
4

2 に答える 2

2

マップの entrySet で Iterator を使用できます - map.entrySet().iterator()

マップを繰り返し処理している間は、他に何もマップを変更していないことを確認してください。

- only remove items using the iterator's remove() method, and
- only modify a value by using the Map.Entry setValue() method

http://docs.oracle.com/javase/6/docs/api/java/util/Map.html#entrySet()を参照してください。

于 2012-07-07T00:20:33.807 に答える
0

反復中にコレクションを変更するには、ListIterationインターフェイスを使用する必要があります。

http://docs.oracle.com/javase/6/docs/api/java/util/ListIterator.html

于 2012-07-07T00:03:28.013 に答える