How to Insert node at the end of a Singly Linked List in Java ?

By | June 17, 2020

In the previous post, How to insert a node at the beginning of a Singly Linked List in Java, we learned, How to Insert a Node at the beginning of the Singly LinkedList.

In this post, We will learn How to Insert a node at the end of a Singly Linked List in Java?

Singly LinkedList is a Data Structure used to store the collection of nodes and having the following properties:

  1. It has a sequence of nodes.
  2. Every Node has two parts, the first part is data, and the second part is the reference to the next node in the List.
  3. First Node is called head Node.
  4. Last node always point to NULL

Singly LinkedList

Inserting a Node at the End of a Singly Linked List:

Inserting a new Node at the End of a Singly Linked List:

CASE 1: If Linked List is empty Then adding newNode at End:

CASE 2: If Linked List is not empty, Then adding a newNode at End:

Output of this Program:

20->10->null
Adding two newNodes 30 and 40 at last…
20->10->30->40->null

 

You May Also Like:

That’s all about the How to Insert node at the end of a Singly Linked List in Java?
If you have any feedback or suggestion please feel free to drop in below comment box.

Leave a Reply

Your email address will not be published.