Skip to content
  • Facebook
GeekCer Logo

GeekCer

The geek's Coding education and Review centre

  • Home
  • Tutorials
    • Java
    • Servlet
    • JSP
    • Python
    • C Tutorial
    • Spring
    • Spring Boot
    • MongoDB
    • Hibernate
    • Data Structure
  • General Knowledge
  • Biography
  • Grammar
  • Festival (त्योहार)
  • Interview
  • Differences
  • Important
  • Toggle search form

Home » Java » Java LinkedList

  • What is Noun
    What is a Noun? 5 Types of Nouns with Examples, Noun diagram Grammar
  • MS Dhoni (Mahendra singh Dhoni) Cricket Biography in Hindi
    MS Dhoni (Mahendra singh Dhoni) Cricket Biography in Hindi Biography
  • Kapil Sharma Show, Comedy Show in Hindi
    Kapil Sharma Show, Comedy Show in Hindi Biography
  • जन्माष्टमी व्रत पूजा विस्तार से | दही हांडी | Krishna Janmashtami Puja
    जन्माष्टमी व्रत पूजा विस्तार से, दही हांडी: Krishna Janmashtami Puja Festival
  • National Doctors Day in India and Other Countries, July 1, 2022
    National Doctors Day in India and Other Countries, July 1, 2022 General Knowledge
  • Draupadi Murmu Biography In Hindi | द्रौपदी मुर्मू की जीवनी
    Draupadi Murmu Biography In Hindi | द्रौपदी मुर्मू की जीवनी Biography
  • State the Universal law of gravitation | Law of Gravity, Formula
    State the Universal law of gravitation | Law of Gravity, Formula Science
  • Elon musk Hindi : एलन मस्क हिंदी में, Autobiography,  Net Worth
    Elon musk Hindi : एलन मस्क हिंदी में, Autobiography,  Net Worth Biography

Java LinkedList

Posted on August 16, 2021October 20, 2021 By GeekCer Education No Comments on Java LinkedList
Java LinkedList

Java LinkedList contains the elements in the form of nodes. It is the implementation class of the List interface which uses doubly linked list store elements.

LinkedList is very convenient to store data and inserting and deleting elements in LinkedList is faster so it takes the less and same amount of time.

Table of Contents

  • Key points about Java LinkedList
    • When should you use LinkedList?
  • Constructors of ArrayList
          • Note:
  • Methods of Java LinkedList
    • Difference between a Stack and LinkedList
    • Program using Java LinkedList
    • Example of Generic LinkedList in Java
          • References:

Key points about Java LinkedList

  • LinkedList preserves insertion order and also allows duplicate elements.
  • null insertion is possible in LinkedList, so you can insert any number of null.
  • .LinkedList in java implements Serializable and Cloneable interfaces but not RandomAccess interface.
  • You can insert Homogeneous as well as Heterogeneous objects into it.
  • LinkedList class is not synchronized.

When should you use LinkedList?

When your frequent operation is to add and remove items from the beginning, middle or end of the list then you should use LinkedList.

Constructors of ArrayList


LinkedList list = new LinkedList();

LinkedList list = new LinkedList(Collection c);

Note:

You can use LinkedList to implement Stacks & Queues.

Methods of Java LinkedList

Following are the basic methods that you can use to add, remove and manipulate elements in LinkedList.

MethodsDescription
boolean add(E obj)This method adds the element to the LinkedList and if the element is added successfully then it returns true.
void addFirst(E obj)Adds the element at the first position.
void addLast(E obj)Adds the element at the last position.
void add(int position, E obj)Adds the elements at the specified position.
E removeFirst()This method returns the element from the first position and then returns it.
E removeLast() This method returns the element from the last position and then returns it.
E getFirst()Gets the element from first position.
E getLast()Gets the element from the last position.
int size()This method returns the number of elements present in the LinkedList.

Difference between a Stack and LinkedList

The purpose of a Stack is to evaluate expressions where a LinkedList stores and retrieves data.

In a stack, insertions and deletions are possible only from the top. In case of LinkedList, it is possible to insert and delete from anywhere.

Program using Java LinkedList

                  import java.util.LinkedList;

public class LinkedListProgram {
  public static void main(String args[]) {
    LinkedList linkedList = new LinkedList();
    linkedList.add("Item 1");
    linkedList.add("Item 2");
    linkedList.add("Item 3");
    linkedList.add("Item 4");

    System.out.println("LinkedList:  " + linkedList);
  }
}

Example of Generic LinkedList in Java

Here is the example of the generic LinkedList. If you specify a particular data type in the LinkedList then you can insert only that types of elements.


LinkedList<String> list = new LinkedList<String>();

LinkedList<Double> list = new LinkedList<Double>(30);

References:

https://docs.oracle.com/javase/7/docs/api/java/util/Lin…

Share this:

  • Click to share on Facebook (Opens in new window)
  • Click to share on WhatsApp (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • More
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Pinterest (Opens in new window)

Also Read

Java

Post navigation

Previous Post: Java ArrayList
Next Post: Vector in Java Collection, Constructors, Example Programs

More Related Articles

Java 11 new Features (With example Programs) Java 11 new Features (With example Programs) Important
Concurrent collections in Java, details, advantages, examples Concurrent collections in Java, details, advantages, examples Java
Java Switch Case Java Switch Case : Switch fall-through, default, break, examples Java
Java Comments Java Comments : Types of java comments, Syntax & Examples Java
Fork/Join Framework in Java | RecursiveTask, RecursiveAction Fork/Join Framework in Java | RecursiveTask, RecursiveAction Java
Importance of Thread Synchronization in Java Thread Synchronization in Java | Synchronized Method & Block Java

Leave a Reply Cancel reply

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

  • Java Home
  • Java Comments
  • Java Variables
  • Java Data Types
  • Java Keywords
  • Java Operators
  • Java If-else Statement
  • Java Switch
  • Java Loop
  • Java Arrays
  • Method Overloading in Java
  • Java OOP
  • Java Collections
  • Java ArrayList
  • Java LinkedList
  • Java Vector
  • Multithreading in java
  • Thread Synchronization
  • Exception Handling
  • Java JDBC Driver
  • Java Database Connectivity steps
  • Lambda Expressions
  • Concurrent Collections
  • National Farmers Day in Hindi | राष्ट्रीय किसान दिवस पर निबंध | चौधरी चरण सिंह जयंती
  • Human rights day in Hindi: 10 दिसंबर ह्यूमन राइट्स डे
  • Unicef day is celebrated on December 11 | Speech on unicef day
  • Indian Navy Day: जल सेना दिवस कब और क्यों मनाया जाता है?
  • P V Sindhu Biography in Hindi, Badminton, State, Caste पी. वी. सिंधु जीवन परिचय, कहानी, राज्य, जाति
  • Draupadi Murmu Biography In Hindi | द्रौपदी मुर्मू की जीवनी
  • Network kya hai (नेटवर्क क्या है)
    Network kya hai (नेटवर्क क्या है) Networking
  • OSI Model | 7 Layers of OSI Model in Computer network
    OSI Model | 7 Layers of OSI Model in Computer network, Functions Networking
  • IPv4 Vs IPv6 | Difference between IPv4 and IPv6
    IPv4 Vs IPv6 | Difference between IPv4 and IPv6 Differences
  • TCP/IP Model, Full Form, Layers and their Functions
    TCP/IP Model, Full Form, Layers and their Functions Networking
  • Similarities and difference between OSI and TCP/IP model
    OSI vs TCP/IP Model, Similarities and difference between OSI and TCP/IP model Networking
  • Difference between Internet and Intranet
    Difference between Internet and Intranet Differences
  • Difference between TCP and UDP
    Difference between TCP and UDP | TCP vs UDP examples Differences
  • Java Tutorial
  • Servlet Tutorial
  • JSP Tutorial
  • Maven Tutorial
  • HTML Tutorial
  • Programs
  • Hindi/English Grammar
  • Difference Between ... and ...
  • HR Interview
  • Important Articles

Write to Us:
geekcer.code@gmail.com

  • About Us
  • Privacy and Policy
  • Disclaimer
  • Contact Us
  • Sitemap

Copyright © GeekCer 2022 All Rights reserved