How to add elements in LinkedList

In this post we will see how to add elements in LinkedList.

Elements can be added to LinkedList either using add(E e) which adds elements at the end of the list OR add(int index, E element) which adds elements to a specified position.

Note that index parameter starts from 0. So if you want to add element to the 2nd position then index will be 1.
Lets see an example using both the methods


We can add elements to Linked List using addFirst and addLast methods as well.
You can get more details here – addFirst and addLast methods in LinkedList


LinkedList API

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