- 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 AbstractCollection class
The addAll() method of the AbstractCollection class in Java is used to add all of elements in the specified collection to this collection. It returns TRUE if the elements are successfully appended
The syntax is as follows:
public boolean addAll(Collection<? extends E> c)
Here, c is the collection containing elements that is to be added to this collection.
To work with AbstractCollection class in Java, import the following package:
import java.util.AbstractCollection;
The following is an example to implement AbstractCollection addAll() method in Java:
Example
import java.util.ArrayList; import java.util.AbstractCollection; public class Demo { public static void main(String[] args) { AbstractCollection<Object> absCollection1 = new ArrayList<Object>(); absCollection1.add("These"); absCollection1.add("are"); absCollection1.add("demo"); absCollection1.add("elements"); System.out.println("AbstractCollection1: " + absCollection1); AbstractCollection<Object> absCollection2 = new ArrayList<Object>(); absCollection2.add("Appended"); absCollection2.add("elements"); System.out.println("AbstractCollection2: " + absCollection2); // appending absCollection1.addAll(absCollection2) ; System.out.println("Displaying elements in the AbstractCollection2: " + absCollection1); } }
Output
AbstractCollection1: [These, are, demo, elements] AbstractCollection2: [Appended, elements] Displaying elements in the AbstractCollection2: [These, are, demo, elements, Appended, elements]
Advertisements