Introduction of Linked List in Java

      Comments Off on Introduction of Linked List in Java

What is Linked List in Java :

Linked List in java is a class that implements “List” interface. Linked List is a data structure that is used to hold or store objects in a structured manner. Linked List has a node that holds object and the address of next node. The first node is called “head” and last node is called as “tail”. The “head” holds the address of first node in the linked list java and the last node has “null” address value means last node does not have any address of next node (last node is the last item of this linked list).

linked-list-java

In the above image, you can see each node has two parts : value of object and address of the next node.

The Head node holds the address value of first node and first node stores 21 as the value of an object of type Integer and 3500 as the address of next node.

The second node stores the 38 as the value of an object of type Integer and 3900 as the address of next node.

The third and last (Tail) node stores 10 as the value of an object of type Integer and null as the address of next node (Means there is no next node after the last node).

Why Linked List in Java ?

As we know that the Array stores the same data type of values and the size of the Array is pre- defined and later if you want to add any value of same data type in an Array at the run time then it was not possible in an Array.

Here to overcome this issue we use Linked List. Linked list allows dynamic memory allocation at run time means you can add any number of values in linked list during the execution of java program. See more below in advantages of linked list in java

Type of Linked List in Java :

  1. Singly Linked List
  2. Doubly Linked List
  3. Circular Linked List

Linked List Operations :

  1. Insert
  2. Delete
  3. Search
  4. Sort
  5. Print

Advantages of Linked List in Java :

  1. Linked List is easy to use.
  2. Linked List can grow and shrink during the run time.
  3. Linked List.is easy to insert and delete objects
  4. Efficiently utilize the memory space.
  5. Linked List provides problem solving approach
  6. Linked List allow dynamic memory allocation.

Disadvantages of Linked List in Java :

  1. Linked List needs more memory space for storing next node address as compared to Array.
  2. Linked List is nor ordered by Index Position
  3. Accessing object is more difficult as compared to Array.
  4. To get the required object, Linked List has to traverse all the preceding objects.