removeFirst and removeLast in LinkedList

Apart from the usual remove() , remove(int index) and remove(Object o) we can use 4 other methods to remove elements from LinkedList.

The 4 methods are (details taken from LinkedList javaDoc)

1. removeFirst() – Removes and returns the first element from this list.

2. removeFirstOccurrence(Object o) – Removes the first occurrence of the specified element in this list (when traversing the list from head to tail).

3. removeLast() – Removes and returns the last element from this list.

4. removeLastOccurrence(Object o) – Removes the last occurrence of the specified element in this list (when traversing the list from head to tail).

Example

Output

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn