title: Return Map.Entry in Java
body: <p>This is probably a dumb question, but how do I return a Map.Entry pair in java?</p>
  
  <p>Given a method like:</p>
  
  <pre><code>public Map.Value&lt;K,V&gt; next(){
  
    return ???
  }
  </code></pre>
  
  <p>How do I build and return the map value?  This is inside of an iterator I'm implementing for a Hash Map.  I have no problems getting the values I want to return, but java doesn't let me instantiate a Map.Entry object unless I implement all the abstract methods, and even then it's not working.  Do I need to build a constructor for the Map.Entry which can be passed the K,V values I'm pulling?</p>
  
  <p>Any help/guidance greatly appreciated</p>
  
  <p>UPDATE</p>
  
  <p>I'm trying to implement an iterator for a custom HashMap, and need to implement the next() method - the structure of my code is:</p>
  
  <pre><code>@Override
   public Iterator&lt;Map.Entry&lt;K, V&gt;&gt; iterator() {
       return new Iterator&lt;Map.Entry&lt;K, V&gt;&gt;(){
  
  
          public boolean hasNext(){
                  return false;
           }
  
           public Map.Entry&lt;K,V&gt; next(){
               Map.Entry&lt;K, V&gt; retVal = new Map.Entry&lt;K, V&gt;() {
  
                   public Map.Entry&lt;K, V&gt;(K key, V val){
  
                   }
                  @Override
                  public K getKey() {
                      // TODO Auto-generated method stub
                      return null;
                  }
  
                  @Override
                  public V getValue() {
                      // TODO Auto-generated method stub
                      return null;
                  }
  
                  @Override
                  public V setValue(V value) {
                      // TODO Auto-generated method stub
                      return null;
                  }
              };
  
  
               }
  
               return null;
           }
  
           public void remove(){
               throw new UnsupportedOperationException();
           }
  
  
       };
   }
  
  }
  </code></pre>
  
  <p>I've got the abstract methods in there, but I'm not sure how I should implement them.  Thanks again for the help</p>