Vector class removeAll(Collection> c) method example
Removes from this Vector all of its elements that are contained in the specified Collection.
Vector class removeAll(Collection c) method example. This example shows you how to use removeAll(Collection c) method.This method Removes from this Vector all of its elements that are contained in the specified Collection.
Here is the code:-
/*
* @Program that Removes from this Vector all of its elements that are contained
in the specified Collection.
* RemoveAll.java
* Author:-RoseIndia Team
* Date:-26-May-2008
*/
import java.util.*;
public class RemoveAll {
public static void main(String[] args) {
//Creating linked list
LinkedList l = new LinkedList();
l.add("Girish");
l.add("Prakash");
l.add("Darshan");
l.add("Neeraj");
//Creating Vector
Vector v = new Vector();
v.add("Deepak");
v.addAll(l);
Enumeration e = v.elements();
System.out.print("Elements of the vector after adding collection is : ");
while (e.hasMoreElements()) {
System.out.print(e.nextElement() + "\t");
}
//Removes from this Vector all of its elements that are contained in the
//specified Collection.
v.removeAll(l);
Enumeration e1 = v.elements();
System.out.println();
System.out.print("Elements of the vector after Removing collection is : ");
while (e1.hasMoreElements()) {
System.out.print(e1.nextElement() + "\t");
}
}
} |
Output of the program:-
Elements of the vector after adding collection is : Deepak Girish Prakash Darshan Neeraj
Elements of the vector after Removing collection is : Deepak |
|