implement singly linked list in java

In this post, we will see how to implement singly linked list in java.
It is one of the most used data structure. In singly linked list, Node has data and pointer to next node. It does not have pointer to the previous node. Last node ‘s next points to null, so you can iterate over linked list by using this condition.
Node for linked list can be presented as below:

An example of linked list:

Let’s implement Linked List in java.

Create a java file named SinglyLinkedList.java.

Lets create Main class named LinkedListMain.java to create LinkedList.

When you run above program, you will get below output:

One Response

  1. Daniel Nguyen April 16, 2017

Add Comment