Vector class removeAllElements() method example
Removes all components from this vector and sets its size to zero.
Vector class removeAllElements() method example. This example shows you how to use removeAllElements() method.This method Removes all components from this vector and sets its size to zero.
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 is : Rose India Rohini
Elements of the vector after removing all elements is: |
|