title: Java - add a node to the end of a list?
body: <p>Here's what I have:</p>
  
  <pre><code>public class Node{
      Object data;
      Node next;
  
      Node(Object data, Node next){
          this.data = data;
          this.next = next;
      }
  
      public Object getData(){
          return data;
      }
  
      public void setData (Object data){
          this.data = data;
      }
  
      public Node getNext(){
          return next;
      }
  
      public void setNext(Node next){
          this.next = next;
      }
  }
  </code></pre>
  
  <p>How do I write the code to add a Node at the end of a list?</p>
  
  <p>So if I had</p>
  
  <pre><code>head -&gt; [1] -&gt; [2] -&gt; null
  </code></pre>
  
  <p>How do I get to</p>
  
  <pre><code>head -&gt; [1] -&gt; [2] -&gt; [3] -&gt; null
  </code></pre>
  
  <p>Actually...I'm not even sure if I have to add to the end. I think it's valid to add and then sort? Not sure.</p>
  
  <p>Thanks!</p>