Java LinkedList class

Java LinkedList class uses doubly linked list to store the elements. It provides a linked-list data structure. It inherits the AbstractList class and implements List and Deque interfaces.

  1. Java LinkedList class can contain duplicate elements.
  2. Java LinkedList class maintains insertion order.
  3. Java LinkedList class is non synchronized.
  4. In Java LinkedList class, manipulation is fast because no shifting needs to be occurred.
  5. Java LinkedList class can be used as list, stack or queue.

Doubly Linked List

In case of doubly linked list, we can add or remove elements from both side.

LinkedList class declaration

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

Constructors of Java LinkedList


It is used to construct an empty list.

LinkedList(Collection c) It is used to construct a list containing the elements of the specified collection, in the order they are returned by the collection's iterator.

Methods of Java LinkedList

void add(int index, Object element) It is used to insert the specified element at the specified position index in a list.

void addFirst(Object o) It is used to insert the given element at the beginning of a list.

void addLast(Object o) It is used to append the given element to the end of a list.

int size() It is used to return the number of elements in a list

boolean add(Object o) It is used to append the specified element to the end of a list

boolean contains(Object o) It is used to return true if the list contains a specified element.

boolean remove(Object o It is used to remove the first occurence of the specified element in a list.


Flash Soon

Copyright ©2017 Design& development by HN