Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Linked List Add Node To Tail
public class LinkedList<T> {
// Reference to the head node
Node head;
public void addToTail(T data){
// create new node
Node newNode = new Node(data, null);
// Check if head is null and set new node as head
if(head == null){
head = newNode;
// get head reference
Node current = head;
// iterate until the last node
while( != null){
current =;
// add new node to the tail = newNode;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment