
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 remove Method of Java AbstractCollection Class
If you want to remove an element from the AbstractCollection classs, use the remove() method. It returns TRUE if the elements requested to be removed is successfully removed from the collection.
The syntax is as follows:
public boolean remove(Object ob)
Here, ob is the element to be removed the from this Collection. Whereas, the class Object is the root of the class hierarchy.
To work with AbstractCollection class in Java, import the following package:
import java.util.AbstractCollection;
The following is an example to implement AbstractCollection remove() method in Java:
Example
import java.util.Iterator; 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("Laptop"); absCollection.add("Tablet"); absCollection.add("Mobile"); absCollection.add("E-Book Reader"); absCollection.add("SSD"); absCollection.add("HDD"); System.out.println("AbstractCollection = " + absCollection); absCollection.remove("Tablet"); absCollection.remove("SSD"); System.out.println("Collection after removing some 2 elements = " + absCollection); } }
Output
AbstractCollection = [Laptop, Tablet, Mobile, E-Book Reader, SSD, HDD] Collection after removing some elements = [Laptop, Mobile, E-Book Reader, HDD]
Advertisements