Trouble with an inner iterator classes remove method
<p>Hi I am making a linked list data structure and within the list I define an iterator inner class. I am currently having trouble with the remove method. The functionality that I want is that it cannot be called on the if the next has not been called or the current element in the list has been removed already. Here's what I have.</p>

<pre><code>private class ListItr implements java.util.Iterator&lt;E&gt;{
private Node&lt;E&gt; currentNode;
private Node&lt;E&gt; nextNode;
private Node&lt;E&gt; previousNode;


public ListItr(List&lt;E&gt; theList){
  previousNode = new Node&lt;E&gt;(null);
  currentNode = new Node&lt;E&gt;(null);
  nextNode = theList.head;
  currentNode.setSuccessor(nextNode);
}

public boolean hasNext(){        
  return nextNode != null;
}

public E next(){
  if(nextNode == null)
    throw new NoSuchElementException();

  previousNode = currentNode;
  currentNode = nextNode;
  nextNode = nextNode.getSuccessor();

  return currentNode.getElement();
}

public void remove(){
  if(currentNode == null)
    throw new IllegalStateException();
  nextNode = currentNode.getSuccessor();
  previousNode.setSuccessor(nextNode);
  currentNode = null;

  size--;
}
</code></pre>

<p>}</p>

<p>As you can see this will successfully remove the node in the list by splicing around it, setting the current node to null. However if it is called on the first without calling next, it will still run when I do not want it to. I can hack around it by adding a flag nextNotCalled, setting it to true in the constructor, then setting it false when next is called however I feel that that is not the way to go about it...</p>
