Collection Framework - LinkedList Class

The implementation of LinkedList in Java is based on the doubly linked list datastructure.

All the elements store the memory locations for the previous and the next elements with the exceptions being first and the last element. The first element doesnt store the previous node info and the last element doesnt store the next node info.

LinkedList Implementation


In Java, LinkedList comes with two constructors :

LinkedList() - default constructor
LinkedList(Collection<? extends E> coll) - creates a linkedlist object from the given collection

An example of linkedlist can be found here

Stack is a legacy class. We can even use LinkedList to implement Stack. Since it already provides addLast() and removeFirst() methods. Stack is based on LIFO (last in first out)

Same thing holds true for Queue. We have  addLast(), removeFirst() methods for the same.

Comments

Popular posts from this blog

Collection Framework - HashSet And LinkedHashSet class

Collection Framework - Cursors in Java

Hashed data structures