- 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
How to add elements to AbstractCollection class in Java?
To add elements to the AbstractCollection class, use the add() method. For example −
absCollection.add("These"); absCollection.add("are"); absCollection.add("demo");
To work with AbstractCollection class in Java, import the following package −
import java.util.AbstractCollection;
The following is an example to add elements to AbstractCollection class in Java −
Example
import java.util.ArrayList; import java.util.AbstractCollection; public class Demo { public static void main(String[] args) { AbstractCollection<Object> absCollection = new ArrayList<Object>(); absCollection.add("These"); absCollection.add("are"); absCollection.add("demo"); absCollection.add("elements"); System.out.println("Displaying elements in the AbstractCollection: " + absCollection); } }
Output
Displaying elements in the AbstractCollection: [These, are, demo, elements]
Advertisements