- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
The addAll() method of Java AbstractSequentialList class
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
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]
Advertisements