title: Displaying the contents of a Map over iterator
body: <p>I am trying to display the <code>map</code> i have created using the Iterator.
  The code I am using is:</p>
  
  <pre><code>private void displayMap(Map&lt;String, MyGroup&gt; dg) {
  Iterator it = dg.entrySet().iterator();   //line 1
  while (it.hasNext()) {
      Map.Entry pair = (Map.Entry)it.next();
      System.out.println(pair.getKey() + " = " + pair.getValue());
      it.remove();
     }
  }
  </code></pre>
  
  <p>Class MyGroup and it has two fields in it, named <code>id</code> and <code>name</code>.
  I want to display these two values against the <code>pair.getValue()</code>.
  The problem here is Line 1 never gets executed nor it throws any exception.</p>
  
  <p>Please Help.</p>
  
  <p>PS:  I have tried every method on <a href="http://javahowto.blogspot.in/2006/06/4-ways-to-traverse-map.html" rel="nofollow">this link</a>.</p>