Singly linked list in java

In this post, we will see about singly linked list in java.
Singly linked list is linked list in which each node has data and pointer to next node.
Example

Singly linked list


append method algorithm

  • If head is null, make inserted node head of the linked list
  • If head is not null, traverse to last node and assign last node’s next to inserted node

Complete java program for singly linked list implementation

Create main class to run above program:

Output of above program:

Linked list:
2 -> 9 -> 4 -> 1 -> 7
Deleting first two nodes
Printing Linked list again:
4 -> 1 -> 7

That’s about creating singly linked list in java.

Leave a Reply

Your email address will not be published. Required fields are marked *