Exploring Java Collections – Understanding Linked Lists

Exploring Java Fundamentals - Understanding Linked Lists

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.

wp-content/uploads/2022/05/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.

Buy Me A Coffee

Found this article helpful? Please consider supporting!

Ram
Ram

I'm a full-stack developer and a software enthusiast who likes to play around with cloud and tech stack out of curiosity. You can connect with me on Medium, Twitter or LinkedIn.

Leave a Reply

Your email address will not be published. Required fields are marked *