title: Why does my add() method in LinkedList not working?
body: <p>I just implement <code>add()</code> method in my <code>Linkedlist</code> but it does not really work. I think "current = new Node(node.data);" makes the object point to a new object instead of update the original one but I don't know how to solve it. Is there any way that I can update this node properly? Please help, thanks. </p>
  
  <pre><code>class Node{
      int data;
      Node next; 
      Node(int data){
          this.data = data;
          this.next = null;
      }
      Node(int data, Node next){
          this.data = data;
          this.next = next;
      }
  }
  class LinkedList{
      protected Node head;
      protected int size;
      LinkedList(){};
  
      void add(int data)
      {
          Node node = new Node(data);
          if (head == null) {
              head = node;
          }else {
              Node current = head;
              while(current != null) {
                  current = current.next;
              }
              current = new Node(node.data);
          }
          size++;
      }
      public int getSize() {
          return size;
      }
      public String toString()
      {
          Node current = head;
          String result = "";
          while(current != null) {    
              result += current.data +"-&gt;";
              current = current.next;
          }
          return result;
      }
  }
  </code></pre>