Category Archives: Interview Questions

How to remove the last node from a Singly Linked List in Java

In this post, We will learn How to remove the last node from a Singly Linked List in Java? Program Logic to Remove/Delete Last node from Singly Linked List: Node<T> lastNode = head; Node<T> previousToLastNode = null; while(lastNode.next != null) { previousToLastNode = lastNode; lastNode = lastNode.next; } previousToLastNode.next = null; Complete Source Code:

Output Of… Read More »