Linkedlist in Java


LinkedList are a very common way of storing arrays of data. The major benefit of linked lists is that you do not  have to specify a fixed size for your list.

LinkedList in Java
Hierarchy of LinkedList in Java
  • LinkedList is a implementation class of List and Queue and Deque Interface and Extends AbstractSequentialList.
  • It is introduced in version 1.2 v.
  • Duplicate and Heterogeneous objects are allowed here.
  • Null insertion is possible.
  • Insertion order is preserved.
  • The underlying data structure is double LinkedList.
  • LinkedList preferable whenever frequent operation is insertion or deletion
  • LinkedList grows one element at a time.



Class declaration of Java LinkedList
public class LinkedList<E> extends AbstractSequentialList<E> implements List<E>, Deque<E>, Cloneable, Serializable
 Constructor of Java Linked List
Constructor Description
LinkedList() It constructs an empty list.
LinkedList(Collection c) It constructs a list containing the elements of the specified collection, in the order they are returned by the collection’s iterator.
Methods in Java LinkedList
Method Description
void add(int index, Object e) It adds element e at specified index.
void addFirst(Object e) It adds object e at the beginning of the list.
void addLast(Object e) It is appends object e at the end of a list.
int size() It returns the number of elements in the list.
boolean add(Object e) It adds the specified element at the end of a list.
boolean contains(Object e) It checks whether object e is present in the list, if yes it will return true otherwise false.
boolean remove(Object e) It removes the first occurrence of object e in the list.
Object getFirst() It returns the first element of the list.
Object getLast() It returns the last element in the list.
int indexOf(Object o) It returns the index in a list of the first occurrence of the specified element, or -1 if the list does not contain any element.
boolean addAll(Collection<? extends E> c) It appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection’s iterator.

One Reply to “Linkedlist in Java”

Leave a Reply