AbstractCollection remove() Method in Java with Examples
The remove(Object O) method of Java AbstractCollection is to remove a particular element from a Collection.
Syntax:
AbstractCollection.remove(Object O)
Parameters: The parameter O is of the type of Collection and specifies the element to be removed from the collection.
Return Value: This method returns True if the element specified in the parameter is initially present in the collection and is successfully removed otherwise it returns False.
Below program illustrate the Java.util.AbstractCollection.remove() method:
Program 1:
// Java code to illustrate remove() import java.util.*; import java.util.AbstractCollection; public class AbstractCollectionDemo { public static void main(String args[]) { // Creating an empty AbstractCollection AbstractCollection<String> abs = new TreeSet<String>(); // Use add() method to add // elements into the Collection abs.add("Welcome"); abs.add("To"); abs.add("Geeks"); abs.add("4"); abs.add("Geeks"); abs.add("TreeSet"); // Displaying the Collection System.out.println("Collection: " + abs); // Removing elements using remove() method abs.remove("Geeks"); abs.remove("4"); abs.remove("TreeSet"); // Displaying the Collection after removal System.out.println("New Collection: " + abs); } } |
Collection: [4, Geeks, To, TreeSet, Welcome] New Collection: [To, Welcome]
Program 2:
// Java code to illustrate remove() import java.util.*; import java.util.AbstractCollection; public class AbstractCollectionDemo { public static void main(String args[]) { // Creating an empty AbstractCollection AbstractCollection<String> abs = new LinkedList<String>(); // Use add() method to add // elements into the Collection abs.add("Welcome"); abs.add("To"); abs.add("Geeks"); abs.add("4"); abs.add("Geeks"); abs.add("LinkedList"); // Displaying the Collection System.out.println("Collection: " + abs); // Removing elements using remove() method abs.remove("Geeks"); abs.remove("4"); abs.remove("LinkedList"); // Displaying the Collection after removal System.out.println("New Collection: " + abs); } } |
Collection: [Welcome, To, Geeks, 4, Geeks, LinkedList] New Collection: [Welcome, To, Geeks]
Recommended Posts:
- AbstractCollection contains() Method in Java with Examples
- AbstractCollection add() Method in Java with Examples
- AbstractCollection retainAll() method in Java with Examples
- AbstractCollection addAll() Method in Java with Examples
- AbstractCollection toString() method in Java with Examples
- AbstractCollection toArray() Method in Java with Examples
- AbstractCollection containsAll() Method in Java with Examples
- AbstractCollection size() Method in Java with Examples
- AbstractCollection isEmpty() Method in Java with Examples
- AbstractCollection clear() Method in Java with Examples
- AbstractCollection in Java with Examples
- AbstractCollection removeAll() method in Java with Example
- Map remove() Method in Java with Examples
- Set remove() method in Java with Examples
- ConcurrentLinkedDeque remove() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



