Card image cap

Exploring Java Collections - Understanding Linked Lists

Java Concepts  • Posted one year ago

LinkedLists are a part of the Collection Framework offered by Java as a part of the java.util package. Collections are data structures which can be used to hold a group of objects together as a single entity and perform operations on top. They are also provided with powerful and useful methods and features which can reduce the overall programming effort.

  1. LinkedList is implemented using Doubly-linked list. It implements java.util.List and Deque interfaces.
  2. A linked list is a data structure consisting of a group of nodes which together represent a sequence.
  3. Under the simplest form, each node is composed of a data and a reference (in other words, a link) to the next node in the sequence in java.
  4. LinkedList extends AbstractSequentialList (abstract class), AbstractSequentialList extends AbstractList in java.

Constructors for Java LinkedList:

  • LinkedList(): This is default constructor of linked list.
  • LinkedList(Collection C): This constructor will add existing collection object to linked list.


data/Admin/linkedlists-program.png



__Output:__
true
true
22

Features of LinkedList:

  • Duplicate elements - LinkedList allows to store duplicate elements in java.
  • Null elements -Null elements can be added in LinkedList in java.
  • Insertion order - LinkedList maintains insertion order if all elements are added using add or addLast method because both method adds elements add element at end of LinkedList.
  • Asynchronous - It is not synchronized (because 2 threads on same LinkedList object can access it at same time) in java.
  • Performance - LinkedList is not synchronized, hence its operations are faster as compared to some other synchronized implementation of List interface in java.
We use cookies to provide you with a great user experience, analyze traffic and serve targeted promotions.   Learn More   Accept