The set() method of Java AbstractSequentialList class


The set() method of the AbtstractSequentialList class is used to replace the element at the specified position in this list with the specified element. It returns the element which is replaced. The syntax is as follows −

E set(int index, E element)

Here, the index is the index of the element to replace. The ele is the element to be stored at the specified position.

To work with the AbstractSequentialList class in Java, you need to import the following package −

import java.util.AbstractSequentialList;

The following is an example to implement AbstractSequentialList set() method in Java −

Example

 Live Demo

import java.util.LinkedList;
import java.util.AbstractSequentialList;

public class Demo {
   public static void main(String[] args) {
      AbstractSequentialList<Integer> absSequential = new LinkedList<>();
      absSequential.add(250);
      absSequential.add(320);
      absSequential.add(400);
      absSequential.add(550);
      absSequential.add(600);
      absSequential.add(700);
      absSequential.add(900);
      System.out.println("Elements in the AbstractSequentialList = "+absSequential);
      System.out.println("Replaced = " + absSequential.set(4,650 ));
      System.out.println("Updated AbstractSequentialList = "+absSequential);
   }
}

Output

Elements in the AbstractSequentialList = [250, 320, 400, 550, 600, 700, 900]
Replaced = 600
Updated AbstractSequentialList = [250, 320, 400, 550, 650, 700, 900]

Updated on: 30-Jul-2019

59 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements