java add an element to the end of a linked list

java add an element to the end of a linked list
refer to:‮ruttual‬i.com
class Node {
    Object data;
    Node next;
    Node(Object d,Node n) {
        data = d ;
        next = n ;
       }

   public static Node addLast(Node header, Object x) {
       // Save the reference to the header so that we can return it.
       Node ret = header;

       // Check if header is null.
       if (header == null) {
           return new Node(x, null);
       }

       // Loop until the end of the list
       while ((header.next != null)) {
           header = header.next;
       }

       // set the new node to the Object x, next will be null.
       header.next = new Node(x, null);
       return ret;
   }
}
Created Time:2017-08-30 09:49:13  Author:lautturi