Add elements in LinkedList

We can use add() method of LinkedList to insert new elements to LinkedList There are 6 overloaded “add” methods defined in LinkedList 1) boolean add(Object o); 2) void add(int index, Object o); 3) boolean addAll(Collection

Share this article on

Methods in LinkedList

boolean add(Object element) It adds an element to the end of the list. list.add("java"); list.add(“java”); Above line adds the string “java” to the end of the linked list. void add(int index, Object item) It adds an element at the given index of the list. list.add(2, "welcome"); list.add(2, “welcome”); This will add the string “welcome” at […]

Share this article on
< Previous Next >