Tutorials

Java Collection Framework


Java LinkedList


LinkedList class belongs to java.util package.

It implements List, Deque, Cloneable and Serializable interface. LinkedList is the doubly-LinkedList implementation of the List and Deque interface.

 

Declaration of LinkedList class


public class LinkedList extends AbstractSequentialList implements List, Deque, Cloneable, Serializable

 

Key features of LinkedList

1.      It is non-synchronized.

2.      LinkedList is preferred over ArrayList if operations like insertion or deletion needs to be done in bulk.

3.      LinkedList allows addition of null element.

 

Create LinkedList in java

  • LinkedList myList = new LinkedList ();   
  • LinkedList myList = new LinkedList (Collection c);

Simple Example:

 

package javaRadarLinkedList;
import java.util.LinkedList;

public class SimpleLinkedList {

      public static void main(String[] args) {

            //create LinkedList

            LinkedList javaRadarList = new LinkedList();

            //Add elements to LinkedList

            javaRadarList.add("Java");

            javaRadarList.add("Spring");

            javaRadarList.add("Hibernate");

            javaRadarList.add("EJB");

            System.out.println(javaRadarList);

      }
}

Now let’s look at different ways in which you can use the LinkedList that you created.

 

LinkedList operations

Traverse LinkedList

Convert

  • LinkedList to ArrayList

ArrayList or LinkedList. Which one to use?(Click to see the difference between two and decide)

 

Difference      

  • ArrayList vs LinkedList
  • LinkedList vs Vector

 



Please Share this page
Views : 67