title: add method of linked list java
body: <p>When adding a node to a linked list I guess the idea would be as follows:</p>
  
  <pre><code>Declare newNode 
  Add to the front if front == null
  else if there is already a node in the list
  </code></pre>
  
  <p>However this does not seem to work</p>
  
  <pre><code>public boolean add (E e) {
  
    ListNode&lt;E&gt; newNode = new ListNode&lt;E&gt;(e,null);
  
    if (front == null){
        front = newNode;
        rear = newNode;
        objectCount++;
        return true;
    }
  
        front.next = newNode;
        rear.next = newNode;
        rear = newNode;
        objectCount++;
        return true;
  }
  </code></pre>
  
  <p>but when I run this for the list "a","b","c","d","e" it doesn't return a list size of 5 but of size 2. What's going wrong here?</p>