title: addFirst() method in Deque implementation
body: <p>I am trying to implement a Deque in java using linked list. As a start I want to implement the method <code>addFirst()</code>. Here is the problem I am getting -- when I add few Strings, for example, "one", "two" and "three", it is inserting correctly, but when iterating the deque, it is only giving the last added object, not all the objects. Is there anything I am missing?</p>
  
  <pre><code>public class Deque&lt;Item&gt; implements Iterable&lt;Item&gt; {
    private Node first;
    private Node last;
    private int N;
  
    public Iterator&lt;Item&gt; iterator() { return new DequeIterator(); }
  
    private class Node {
      private Item item;
      private Node next;
    }
  
    public Deque() {
      first = null;
      last = null;
      N = 0;
    }
  
    public boolean isEmpty() { return first == null || last == null; }
    public int size() { return N; }
  
    public void addFirst(Item item) {
    if (null == item) { throw new NullPointerException("Can not add a null value"); }
    Node oldFirst = first;
    first = new Node();
    first.item = item;
    first.next = null;
  
    if (isEmpty()) {
      last = first;
    } else {
      oldFirst.next = first;
    }
  
    N++; 
   }
  
   private class DequeIterator implements Iterator&lt;Item&gt; {
     private Node current = first;
  
     public boolean hasNext() { return current != null; }
     public void remove() { throw new UnsupportedOperationException(); }
  
     public Item next() {
      if (!hasNext()) { throw new NoSuchElementException(); }
      Item item = current.item;
      current = current.next;
      return item;
     }
  
   }
  
   public static void main(String args[]) {
     Deque&lt;String&gt; deque = new Deque&lt;String&gt;();
     deque.addFirst("one");
     deque.addFirst("two");
     deque.addFirst("three");
     deque.addFirst("four");
  
     for (String s : deque) {
       System.out.println(s); // prints only "four"
     }
   }
  }
  </code></pre>