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:

Was this post helpful?


import_contacts

You may also like:

Related Posts

  • 12 August

    Intersection of two linked lists

    Table of ContentsProblemSolutionWas this post helpful? If you want to practice data structure and algorithm programs, you can go through 100+ java coding interview questions. In this post, we will see how to find Intersection of two linked lists. Problem Given two singly linked lists, find if two linked lists intersect. If they intersect, find intersection point. […]

  • 12 October

    Implement Queue using Linked List in java

    If you want to practice data structure and algorithm programs, you can go through 100+ java coding interview questions. In this post , we will see how to implement Queue using Linked List in java. Queue is abstract data type which demonstrates First in first out (FIFO) behaviour. We will implement same behaviour using Array. Although java provides implementation […]

  • 10 October

    Convert sorted Linked List to balanced BST

    Table of ContentsJava Program to convert sorted LinkedList to balanced BST:Was this post helpful? If you want to practice data structure and algorithm programs, you can go through 100+ java coding interview questions. In this post , we will see how to convert sorted LinkedList to balanced binary search tree. There are two ways to do […]

  • 20 September

    Find length of Linked List in java

    Table of ContentsJava program to find length of LinkedList:Was this post helpful? If you want to practice data structure and algorithm programs, you can go through data structure and algorithm programs. In this post, we will see how to find length of Linked List in java. You can obviously use size() method of java Linked List […]

  • 10 September

    Implement stack using Linked List in java

    If you want to practice data structure and algorithm programs, you can go through 100+ java coding interview questions. In this program, we will see how to implement stack using Linked List in java. The Stack is an abstract data type that demonstrates Last in first out (LIFO) behavior. We will implement the same behavior using […]

  • 01 April

    How to check if linked list is palindrome in java

    Table of ContentsJava Linked List Interview Programs:Algorithm:Was this post helpful? In this post, we will see how to check if linked list is palindrome or not. Java Linked List Interview Programs: How to reverse a linked list in java How to reverse a linked list in pairs in java How to find middle element of […]

Comments

  1. This was the best implementation of Linked List in java I’ve seen on the internet. Thank you so much, cleared all my concepts.

Leave a Reply

Your email address will not be published.

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.