title: How can I get the key as well as the value in an apex for loop?
body: <p>I have a map object which stores <code>&lt;Id, String&gt;</code> where the Id is a contact Id, and the String is a generated email message.</p>
  
  <p>I have successfully looped through the map and have been able to pull out the values (The String portion) as I iterate through the map.</p>
  
  <p>What I would like to be able to do is also grab the key when I grab the value.  This is very simple to do in most languages, but I can't seem to find out how to do it in apex.</p>
  
  <p><strong>This is what I have right now:</strong></p>
  
  <pre><code>Map&lt;Id,String&gt; mailContainer = new Map&lt;Id,String&gt;{};
  
  for(String message : mailContainer.values())
  {
  
      // This will return my message as desired
      System.debug(message);
  
  }
  </code></pre>
  
  <p><strong>What I would like is something like this:</strong></p>
  
  <pre><code>for(String key=&gt;message : mailContainer.values())
  {
  
      // This will return the contact Id
      System.debug(key);
  
      // This will return the message
      System.debug(message);
  
  }
  </code></pre>
  
  <p>Thanks in advance!</p>