The add() method of Java AbstractSequentialList class


The AbstractSequentialList class has the add(int index, E ele) method to add element to the specific position. You can also use the add() method inherited from AbstractList class.

add(int index, E ele) method

The syntax is as follows:

add(int index, E ele)

Here, index is where the element is to be inserted. The ele is the element to be inserted.

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 add() 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(0, 50);
      absSequential.add(1, 30);
      absSequential.add(2, 80);
      absSequential.add(3, 150);
      absSequential.add(4, 110);
      absSequential.add(5, 200);
      absSequential.add(6, 350);
      System.out.println("Elements in the AbstractSequentialList = "+absSequential);
   }
}

Output

Elements in the AbstractSequentialList = [50, 30, 80, 150, 110, 200, 350]

add() method

The add() method inserts elements in the List:

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(10);
      absSequential.add(25);
      absSequential.add(60);
      absSequential.add(70);
      absSequential.add(195);
      System.out.println("Elements in the AbstractSequentialList = "+absSequential);
   }
}

Output

Elements in the AbstractSequentialList = [10, 25, 60, 70, 195]

Updated on: 30-Jul-2019

47 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements