Map<String, String> SecondMap= new Map<String, String>();
SecondMap.put('IndexValue', 'Value');

Map <String,Map <String,String>> FirstMap= new Map <String,Map<String,String>>();
FirstMap.put('IndexValue', new Map<String, String>());

for(String key1:FirstMap.keySet()) {
  for(String key2:FirstMap.get(key1).keySet()) {
    for(SecondMap.put(FirstMap.put(key1).get(key2))) {


I have two maps both have the parameters to insert, I need to insert the parameters of the secod map in the first map, I tried to create these loops but I did not succeed


The method putAll() copies all of the key-value pairs from a Map into another Map.

Map<String, String> mapOne = new Map<String, String>{ 'Test' => 'Test!' };
Map<String, String> mapTwo = new Map<String, String>{ 'Foo' => 'Bar' };

// mapOne now equals { 'Test' => 'Test!', 'Foo' => 'Bar' }

It's not clear whether you're operating with a nested Map or not. If you are, and you're trying to add keys to a second-level (nested) Map, simply obtain the nested Map to which you wish to add values and call putAll() on that instance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.