Monday, 25 May 2015

How to Remove List From Vector

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

public class RemoveList {
   
      public static void main(String[] args) {
           
             Vector<String> vector = new Vector<String>();
             //add element in vector
             vector.add("cricket");
             vector.add("hockey");
             vector.add("football");
             vector.add("tennish");
           
             // print vector
             System.out.println("Vector = "+vector);
           
             List<String> list = new ArrayList<String>();
             list.add("hockey");
             list.add("tennish");
             list.add("apple");
             list.add("java");
           
             System.out.println("list is = "+list);
           
             /*
              * Removes from this Vector all of its
              *  elements that are contained in the
              *  specified Collection.
              */
             vector.removeAll(list);
           
             System.out.println("Vector after remove list = "+vector);
                   
                }

}


Output:
Vector = [cricket, hockey, football, tennish]

list is = [hockey, tennish, apple, java]

Vector after remove list = [cricket, football]


No comments:

Post a Comment