Replace element in LinkedList in Java

In this tutorial, we will learn how to Replace element in LinkedList in Java.

LinkedList in Java is doubly-linked list implementation of the List and Deque interfaces. LinkedList class extends AbstractSequentialList and implements the List, Deque, and Queue interfaces and permits null elements. LinkedList class in Java provides a method set(int index, E element). We will use this method to replace element in LinkedList in Java. The syntax of set() method is:

Syntax of set() method is:

this method replaces the element at the specified position in this list with the specified element and throws IndexOutOfBoundsException, if the index is out of range.



In the above program, we have replaced element “Guava” in the LinkedList with element “Grapes”.

Related posts

Leave a Comment