title: Java: implementing Treemap methods on map.entry, possible?
body: <p>My assignment is to write code that swaps the keys for the values of a map (with non 1:1) ratio, and I thought to create a <code>TreeMap</code>. So far I have:</p>
  
  <pre><code>   public static Map&lt;String, Set&lt;String&gt;&gt; reverseMapping(Map&lt;String, String&gt; mapping) {
      TreeMap &lt;String, String&gt; temp = (TreeMap&lt;String, String&gt;) mapping;
  
  
      while (temp.pollFirstEntry() !=null ){
           Map.Entry&lt;String, String&gt; iter=temp.pollFirstEntry();
           String newKey = iter.get(iter.firstKey());
      }
  </code></pre>
  
  <p>but it's saying that <code>first.Key()</code> is undefined for map.entry and suggests I cast <code>iter</code>. but that just makes things worse. </p>
  
  <p>How can I achieve my goal of breaking the map entry down into its keys and values in a new set and string, respectively? Is this possible using the starting point I have, or at all?</p>