addFirst and addLast methods in LinkedList

Apart from add(E e) and add(int index, E element) methods, we have addFirst and addLast methods in LinkedList to add elements.

1. addFirst(E e) – Inserts the specified element at the beginning of this list.

2. addLast(E e) – Appends the specified element to the end of this list.

Example : addFirst and addLast methods in LinkedList

Output

Reference

LinkedList API

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