title: Is a for/break more efficient than iterator().next()?
body: <p>It is known that mapX has a single entry in it.  A code metric tool complains about using 'break' inside for loops, but normally, in such a small loop, I'd let it pass.  In this case though, with it known that there's only a single entry, I'm not sure which is more efficient.</p>
  
  <p>So, which of the following is more efficient when you know that the map will only ever contain one element?</p>
  
  <p>Possible replacement:</p>
  
  <pre><code>Map.Entry&lt;String,String&gt; e = mapX.entrySet().iterator().next();
  Y.setMsg(e.getValue());
  Y.setMsgKey(e.getKey());
  </code></pre>
  
  <p>Original code:</p>
  
  <pre><code>for (String key : mapX.keySet()){
      Y.setMsg(mapX.get(key));
      Y.setMsgKey(key);
      break;
  }
  </code></pre>