title: Add node to end of linked list in Java
body: <p>I am working on a homework assignment involving linked lists. We have to implement a queue ADT, and the one method I am having trouble with is adding a node to the end of the list (the enqueue method). Here is my code: </p>
  
  <p>public class Queue implements QueueInterface {</p>
  
  <pre><code>    private Node head;
      private Node tail;
      private int sz;
  
      public  Queue() {
          head = null;
          tail = null;
          sz = 0;
      }
  
      public void enqueue(T newEntry) {
          Node newElement = new Node(newEntry);
          newElement.next = null;
          tail.next = newElement;
          tail = newElement;
      }
  
      public T dequeue() {
          T result = null;
          if(head != null) {
              result = head.data;
              head = head.next;
              sz--;
          }
          return result;
      }
  
      public T getFront() {
          return head.data;
      }
  
      public boolean isEmpty() {
          if (head == null) {
              return true;
          }
          return false;
      }
  
      public void clear() {
          while (!isEmpty()) {
              dequeue();
          }
      }
  
      @Override
      public String toString() {
          return "Queue [head=" + head + ", sz=" + sz + "]";
      }
  
      public class Node {
  
          private Node next;
          private T data;
  
          public Node (T newData) {
              data = newData;
          }
  
          @Override
          public String toString() {
              return "Node [next=" + next + ", data=" + data + "]";
          }
  
      }
  
  }
  </code></pre>
  
  <p>If anyone could help me out with this I would be really appreciative. Thanks for your time! :)</p>