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

  • Mahatma Gandhi Essay in Hindi | Gandhiji Biography
    Mahatma Gandhi Essay in Hindi | Gandhiji Biography Biography
  • Balkand Ramayana story in Hindi | रामायण बाल कांड राम का जन्म
    Balkand Ramayana story in Hindi | रामायण बाल कांड राम का जन्म Spiritual
  • Ramayana Uttar Kand Luv Kush| रामायण उत्तर कांड इन हिंदी
    Ramayana Uttar Kand Luv Kush | रामायण उत्तर कांड इन हिंदी Spiritual
  • Lanka Kand Summary in Hindi | Ram Vs Ravana | लंका काण्ड
    Lanka Kand Summary in Hindi | Ram Vs Ravana | लंका काण्ड Spiritual
  • Lata Mangeshkar Biography In Hindi | लता मंगेशकर संपूर्ण जीवन परिचय
    Lata Mangeshkar Biography In Hindi | लता मंगेशकर संपूर्ण जीवन परिचय Biography
  • Real life Inspirational Stories in Hindi | Success story in Hindi
    Real life Inspirational Stories in Hindi | Success story in Hindi Biography
  • Rabindranath Tagore Biography in Hindi, Poems, Birthday
    Rabindranath Tagore Biography in Hindi, Title of Gurudev Biography
  • Human rights day
    Human rights day in Hindi: 10 दिसंबर ह्यूमन राइट्स डे General Knowledge

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

Difference between Comparable and Comparator Difference between Comparable and Comparator Differences
Fork/Join Framework in Java | RecursiveTask, RecursiveAction Fork/Join Framework in Java | RecursiveTask, RecursiveAction Java
Java ArrayList Java ArrayList Java
Collections in Java Collections in Java Java
Difference between StringBuffer and StringBuilder Difference between StringBuffer and StringBuilder Differences
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 | द्रौपदी मुर्मू की जीवनी
  • TCP/IP Model, Full Form, Layers and their Functions
    TCP/IP Model, Full Form, Layers and their Functions Networking
  • Network kya hai (नेटवर्क क्या है)
    Network kya hai (नेटवर्क क्या है) 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
  • OSI Model | 7 Layers of OSI Model in Computer network
    OSI Model | 7 Layers of OSI Model in Computer network, Functions Networking
  • Difference between TCP and UDP
    Difference between TCP and UDP | TCP vs UDP examples Differences
  • IPv4 Vs IPv6 | Difference between IPv4 and IPv6
    IPv4 Vs IPv6 | Difference between IPv4 and IPv6 Differences
  • Difference between Internet and Intranet
    Difference between Internet and Intranet 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