title: The Iterator interface
body: <p>I have a University assignement that requires me to implement an inner class which implements the Iterator interface. The iterator works on a single-linked list superclass.</p>
  
  <p>Currently my inner class looks like this:</p>
  
  <pre><code>private class ListIterator implements Iterator&lt;V&gt;{
  
      Node temp;
      boolean nextCalled = false;
  
      ListIterator(Node fo){
          this.temp = fo;
      }
  
      @Override
      public boolean hasNext() {
          if(temp != null){
              return true;
          }
          return false;
      }
  
      @Override
      public V next() {
          nextCalled = true;
          return temp.getReprValue();
      }
  
      @Override
      public void remove() {
          if(nextCalled &amp;&amp; hasNext()){
              nextCalled = false;
              removeElement(temp.getReprKey());
              temp = temp.getNext();
          }
  
      }
  
  }
  </code></pre>
  
  <p>Now my problem is that the hasNext() method returns true even when the list is actually empty. Everything else seems to work. I have probably overlooked a logic flaw somewhere, but I cannot find it myself.</p>