title: Retrieving an iterator for a HashMap throws a cast exception
body: <p>I have some relatively simple code I have made that is <strong>supposed to retrieve an iterator to a HashMap &amp; print out the key pair values</strong>.</p>
  
  <p>My problem is that when I go to retrieve the iterator I get this exception thrown.</p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.ClassCastException: java.util.HashMap$Entry cannot be cast to java.lang.String<br>
         at Delete.main(Delete.java:25)</p>
  </blockquote>
  
  <p>Here is my code &amp; I point out where line 25 is:  </p>
  
  <pre><code>    Map &lt;String, UpdatablePage&gt; contentMap = new HashMap &lt;String, UpdatablePage&gt;();
      contentMap.put( "test", new UpdatablePage() );
  
      for ( Iterator it = (Iterator) contentMap.entrySet().iterator(); it.hasNext(); )
      {
          String key = (String) it.next();  // LINE 25
          UpdatablePage value = contentMap.get(key);
          System.out.print( "Key=" + key + ", Value=" + value.toString() );
      }
  </code></pre>
  
  <p>PS, I have tried to iterate over a map using the Map.Entry but when I go to cast the value returned by the iterator to a Map.Entry I get another casting exception, why?  </p>
  
  <pre><code>// Error occurs when I do the following
  Map.Entry pair = (Map.Entry) it.next();
  </code></pre>