The addAll() method of Java AbstractSequentialList class

Java 8Object Oriented ProgrammingProgramming

The addAll() method of the AbstractSequentialList class inserts all the elements in the specified collection into this list at the specified position. Set the specified position as the parameter.

The syntax is as follows:

boolean addAll(int index, Collection<? extends E> c)

Here, index is where you want to insert the first element from the specified collection and c is the collection containing elements to be added to this list.

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 addAll() method in Java:

Example

 Live Demo

import java.util.LinkedList;
import java.util.AbstractSequentialList;
import java.util.ArrayList;
import java.util.Collection;
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);
      Collection<Integer> c = new ArrayList<Integer>();
      c.add(220);
      c.add(250);
      c.add(300);
      absSequential.addAll(3, c);
      System.out.println("Updated AbstractSequentialList = " + absSequential);
   }
}

Output

Elements in the AbstractSequentialList = [10, 25, 60, 70, 195]
Updated AbstractSequentialList = [10, 25, 60, 220, 250, 300, 70, 195]
raja
Published on 01-Apr-2019 13:12:09
Advertisements