The set() method of Java.util.AbstractSequentialList is used to replace any particular element in the sequential list created using the LinkedList class with another element. This can be done by specifying the position of the element to be replaced and the new element in the parameter of the set() method.
AbstractSequentialList.set(int index, Object element)
Parameters: This function accepts two parameters as shown in the above syntax and described below.
- index: This is of integer type and refers to the position of the element that is to be replaced from the list.
- element: It is the new element by which the existing element will be replaced and is of the same object type as the sequential list.
Return Value: The method returns the previous value from the sequential list that is replaced with the new value.
Below programs illustrate the Java.util.AbstractSequentialList.set() method:
AbstractSequentialList:[Geeks, for, Geeks, 10, 20] The Object that is replaced is: Geeks The Object that is replaced is: 20 The new List is:[Geeks, for, GFG, 10, 50]
AbstractSequentialList:[50, 40, 30, 20, 10] The Object that is replaced is: 40 The Object that is replaced is: 10 The new List is:[50, 400, 30, 20, 100]
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.