LinkedList in Java

Here we will see LinkedList in details.

  1. Basic points about LinkedList.
  2. Different ways to iterate LinkedList in Java.
  3. Constructors and methods of LinkedList.
  • LinkedList is a class which implements List, Deque, Cloneable and Serializable interface.
  • LinkedList uses node representation to store the elements.
  • LinkedList store the elements in added order.
  • It allows duplicate elements.
  • We can have null as an element in LinkedList.
  • LinkedList elements can be accessed by using Iterator and ListIterator interface.
  • LinkedList objects are eligible for Serializable and Cloning.

Example –


import java.util.LinkedList;
import java.util.List;

public class LinkedListExample {
	public static void main(String[] args) {
		List<String> listObject = new LinkedList<>();

		listObject.add("ram");
		listObject.add("mohan");
		listObject.add("shyam");
		listObject.add("mohan");
		listObject.add("ram");
		listObject.add(null);

		System.out.println(listObject);

	}
}

Output is –


[ram, mohan, shyam, mohan, ram, null]